Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account?Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress,GenerateBlocks).

Want to become a premium user? Learn more below.

Show only posts with an ACF relationship in Query Block?

  • Hi,

    So I have an archive page template set up (using Elements) for a ‘Services’ ACF CPT, and on that template I have a query loop accordion that also pulls in ‘FAQ’ CPTs.

    What I am trying to achieve is to only show the related/relevant FAQs for each service, but I can’t seem to get it working.

    The FAQ posts have a relationship custom field (related_services) that links these FAQ post items to the Service CPTs they are relevant to. The ACF field group has the relationship set to Post Object, but I have also tried Post ID and can’t seem to get either to work.

    I’ve found a few variations ofthisapproach using a class to filter a merge of post ids, but this doesn’t seem to work for me in this use case.

    Thanks in advance for any help!

  • Hi there,

    Are the FAQ inserted to a query loop block of post-type Services?

    The FAQ posts have a relationship custom field (related_services) that links these FAQ post items to the Service CPTs they are relevant to.

    1. I think it should be reversed, you should set the relationship field in single service CPT.

    2. set the field returning value to Post ID.

    3. You will need to write code to alter the query loop output, as GB does not support relationship fields. Solution would be similar to this:https://generate.support/topic/acf-relationships/page/2/#post-113287

  • Hi Ying,

    Initially the FAQ were inserted through the post type FAQ, but I have changed it to be Services at your recommendation. I’ve also set the returning value to Post ID.

    I’ve updated the code to match the onehere– the class used on the grid block isrelated-faqsand the relationship field isrelated_faqs.

    At present all of the service posts load in the query grid by default on any single service page, but the pages that have a relationship set (to an FAQ CPT) will not load any posts in the query block at all.

  • An update – I’ve set the post type for the query grid back to FAQs and it seems to be working now, not sure how or why but it works.

    Thanks for your help!

  • Yes, the query loop post type should be FAQ, glad it worked 🙂

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.