• I have two query blocks on the same page. They both are almost the same. Each are meta queries pulling from two different custom post types. The meta keys are a custom field in one post type and a custom field in the other post type. Relation between the two is OR. The custom fields are dates and the queries pull all posts from both post types for a certain time frame.

    In the admin editor, the queries show the correct posts. On the frontend, the first query results are correct, but the second query shows only results from one post type.

    I think this is the same issue as a post on here from 9 months ago that never got a resolution.

    https://ww.wp.xz.cn/support/topic/several-aql-blocks-in-same-page-with-meta-key-and-aditional-post-type/

    Let me know if this doesn’t make any sense and I can hopefully explain better, or if you need screenshots, etc.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Ryan Welcher

    (@welcher)

    Hello and thanks for using AQ!

    Sorry you are running in to this! This is an issue I’ve seen before and thought I had resolved. Can you confirm you’re using the latest version of AQL? Also, it would be great to see the settings for each instance if possible.

    Thread Starter Lane

    (@laned69)

    Thanks for your reply.

    I am on the latest version, 4.0.1.

    I am trying to make a “calendar” page where each month’s block shows posts from 3 custom post types that start within that month. Posts have meta field that stores the start date. I have multiple AQL blocks on the page that are all the same except the dates within the meta value.

    Here is the code view of the AQL block for January.

    <!-- wp:query {"queryId":0,"query":{"perPage":10,"pages":0,"offset":0,"postType":"lws_exhibition","order":"asc","orderBy":"meta_value","author":"","search":"","exclude":[],"sticky":"","inherit":false,"parents":[],"format":[],"include_posts":[],"meta_query":{"queries":[{"id":"0b4ac9bc-6df0-4506-b9fb-58ee978f1b1d","meta_key":"lws_exhibition-start-date","meta_value":"2025-01-01,2025-01-31","meta_compare":"BETWEEN"},{"id":"f16c2733-e941-4464-a02e-4bb99e20bdfa","meta_key":"lws_workshop-start-date","meta_value":"2025-01-01,2025-01-31","meta_compare":"BETWEEN"},{"id":"5c79945a-3582-43f9-b164-2ac1adf9d4ed","meta_key":"lws_event-start-date","meta_value":"2025-01-01,2025-01-31T23:59:59","meta_compare":"BETWEEN"}],"relation":"OR"},"multiple_posts":["lws_workshop","lws_event"],"date_query":"","disable_pagination":true},"namespace":"advanced-query-loop"} -->

    Here is what the March query looks like on the front end (from Query Monitor plugin). You can see that one of the post_type is empty. This is what happens for all queries except January

    SELECT wp_xxx_posts.ID
    FROM wp_xxx_posts
    INNER JOIN wp_xxx_postmeta
    ON ( wp_xxx_posts.ID = wp_xxx_postmeta.post_id )
    WHERE 1=1
    AND ( ( wp_xxx_postmeta.meta_key = 'lws_exhibition-start-date'
    AND wp_xxx_postmeta.meta_value BETWEEN '2025-03-01'
    AND '2025-03-31' )
    OR ( wp_xxx_postmeta.meta_key = 'lws_workshop-start-date'
    AND wp_xxx_postmeta.meta_value BETWEEN '2025-03-01'
    AND '2025-03-31' )
    OR ( wp_xxx_postmeta.meta_key = 'lws_event-start-date'
    AND wp_xxx_postmeta.meta_value BETWEEN '2025-03-01'
    AND '2025-03-31T23:59:59' )
    OR ( wp_xxx_postmeta.meta_key = 'lws_exhibition-end-date'
    AND wp_xxx_postmeta.meta_value BETWEEN '2025-03-01'
    AND '2025-03-31' ) )
    AND ((wp_xxx_posts.post_type = ''
    AND (wp_xxx_posts.post_status = 'publish'))
    OR (wp_xxx_posts.post_type = 'lws_event'
    AND (wp_xxx_posts.post_status = 'publish'
    OR wp_xxx_posts.post_status = 'private'))
    OR (wp_xxx_posts.post_type = 'lws_workshop'
    AND (wp_xxx_posts.post_status = 'publish'
    OR wp_xxx_posts.post_status = 'private')))
    GROUP BY wp_xxx_posts.ID
    ORDER BY wp_xxx_postmeta.meta_value ASC
    LIMIT 0, 10

    Let me know if you need anything else.

    Thank you so much for looking into this.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Multiple meta queries on same page’ is closed to new replies.