How to query for custom field within Gutenberg block from outside of that post?

admin2025-06-03  3

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

I created a custom field inside of a custom Gutenberg block (using ACF). It is a Post Object field that accepts multiple post IDs. When inside that post, I can pull the data just fine and everything is working– I can loop through the IDs and output the correct information.

Now, from other posts I want to use WP_Query to find posts that are using that custom block and custom field and are related to the current post, but I can't figure it out. If it were a typical custom field, I'd simply use a meta_key. But this seems more complex because the data is somewhere inside the post_content not the meta where standard custom fields live.

I know my example uses ACF, but I would have this same question whether I created the custom block and field manually or using ACF.

Basically I want to edit a Case Study post and correlate it to different industries (which are other posts). Then, on those individual industry pages I want to query and cross-link related Case Studies.

Can someone point me in the right direction?

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

I created a custom field inside of a custom Gutenberg block (using ACF). It is a Post Object field that accepts multiple post IDs. When inside that post, I can pull the data just fine and everything is working– I can loop through the IDs and output the correct information.

Now, from other posts I want to use WP_Query to find posts that are using that custom block and custom field and are related to the current post, but I can't figure it out. If it were a typical custom field, I'd simply use a meta_key. But this seems more complex because the data is somewhere inside the post_content not the meta where standard custom fields live.

I know my example uses ACF, but I would have this same question whether I created the custom block and field manually or using ACF.

Basically I want to edit a Case Study post and correlate it to different industries (which are other posts). Then, on those individual industry pages I want to query and cross-link related Case Studies.

Can someone point me in the right direction?

Share Improve this question asked Feb 8, 2019 at 21:08 GreatBlakesGreatBlakes 1711 gold badge3 silver badges12 bronze badges 2
  • 1 I could be way off, but I think you're trying to do this, which I requested here: github/AdvancedCustomFields/acf/issues/… It's being considered for ACF, but as Elliot responded, he may not support it. But if you can wait it out, might be worth keeping an eye out for this being added. – Trevor Commented Feb 27, 2019 at 5:43
  • Very similar, thanks for the link. Glad to see Elliot respond to acknowledge it. – GreatBlakes Commented Feb 27, 2019 at 13:36
Add a comment  | 

1 Answer 1

Reset to default 0

This is a bit of a work around, but you could create a Post Meta Block with the Block API, which simply sets a post meta value for a post. Then you could add this block every time you add your ACF custom block, enabling you to query all posts with the ACF custom block.

This tutorial is a great place to start: https://wordpress/gutenberg/handbook/designers-developers/developers/tutorials/metabox/meta-block-1-intro/

Edit: You could also add an ACF-Field on post_type level, which is a lot easier. Set it to not allow null and it wouldn't be possible to forget this field.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748923482a314855.html

最新回复(0)