• Hi there. I love AQL and I surely prefer it over the standard query block.
    In one project I would like to achieve that AQL renders posts of a certain (custom) post type. Unfortunately, until now I was unable to solve the “quest” and I am wondering if there is anyone who might have a similar setting and made it work.

    The setting is as follows:

    I have two CPT. First one is “services”.
    Second CPT is “testimonials” and has one of its meta data/custom fields being (an array of) the services it is related to.

    Now, on a single post page of CPT “services” I would like to render posts of CPT “testimonials” which have custom field set to the post id of the currently displayed service. Does this make sense? 🙂

    Is there a way to accomplish this? It seems like I need to have access to the current post id (as a variable?) to match it against the custom fields of the 2nd cpt in a custom query.

    Any help is greatly appreciated! 🙂

    Cheers

Viewing 4 replies - 1 through 4 (of 4 total)
  • @labemi

    I assume you’re using ACF for your custom post types and custom fields (any other plugin should also work the same).

    So 2 Custom Post types – Services and Testimonials.
    Let’s say you have posts of type Services called Car Cleaning Services and Window Cleaning Services. And on your Testimonials CPT, you have a Custom Field named “Services Offered” and when you create your Testimonial Posts, you input either Car Cleaning Services or Window Cleaning Services in the custom field section.


    TO accomplish what you’re looking for, on your Services post, add the Advanced QUery Loop Plugin, choose “Testimonial” as the Post Type and in the “Post Meta Query” click on Add meta query and under the Meta Key field add the Field Name of the Custom field you want to filter for (which would be Services Offered) and under the Meta Value you can input Car Cleaning Service or Window Cleaning Service.

    So on your Car Cleaning Services post, you add the AQL and choose Post Type as Testimonial, Meta Key as Services Offered and Meta Value as Car Cleaning Service, it will fetch all the posts associated with Car Cleaning Services custom field.

    Thread Starter Lars

    (@labemi)

    thank you so much. But no, I am not using ACF but coded the cpts myself.

    as long as your Custom Post Type is exposed via the REST API and the Custom Fields are pointed to the Custom Post Type, the above steps should work.

    Hopefully this worked for you.

    Plugin Author Ryan Welcher

    (@welcher)

    @labemi sorry for the late response here. This is currently not possible with AQL. I am currently working on a solution to use dynamic placeholders (i.e current post, current date, current user) to be able to do these more advanced things.

    • This reply was modified 8 months, 4 weeks ago by Ryan Welcher. Reason: incorrect ping
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Showing CPT posts within a single post page of another CPT’ is closed to new replies.