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.

ACF Gutenberg block with Post Object custom field

Can someone point me in the right direction?

closed as off-topic by Jacob Peattie, cjbj, Dave Romsey, Rick Hellewell, rudtek Mar 4 at 15:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    I could be way off, but I think you're trying to do this, which I requested here: github.com/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 Feb 27 at 5:43
  • Very similar, thanks for the link. Glad to see Elliot respond to acknowledge it. – GreatBlakes Feb 27 at 13:36

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.org/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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.