• Resolved squasher

    (@squasher)


    Hi,

    I’ve got the following custom wp_query for the tribe_events custom post type. However, I get no results (which it should). After checking the query with the_query->request statement, I saw that the query was very strange.

    This was the code which should do the trick:

    <?php 
     $args = array(
     'post_type'     => 'tribe_events',
     'post_status'   => 'publish', 
     );
    
    // query
    $the_query = new WP_Query( $args );
       /*  Uncomment to see the resulting SQL to debug */
       // echo $the_query->request; die();
    
    ?>
    <?php if( $the_query->have_posts() ): ?>
        <ul>
        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <h2>Test</h2>
            <li>
                <a href="<?php the_permalink(); ?>">
                    <?php the_title(); ?>
                </a>
            </li>
        <?php endwhile; ?>
        </ul>
    <?php endif; ?>

    And this was the query according to the_query->request:

    SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_tec_occurrences 
    ON wp_posts.ID = wp_tec_occurrences.post_id WHERE 1=1 AND ( wp_tec_occurrences.post_id IS NOT NULL AND 
    CAST(wp_tec_occurrences.end_date AS DATETIME) >= '2023-03-20 10:23:49' ) AND wp_posts.post_type = 'tribe_events' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_tec_occurrences.occurrence_id 
    ORDER BY wp_tec_occurrences.start_date ASC, wp_posts.post_date ASC LIMIT 0, 10

    If I check for the post type ‘post’ or ‘tribe_organizer’ I do get expected results. So where does this strange query statement come from?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Darian

    (@d0153)

    Hi @squasher

    Thanks for reaching out. Let me help you with this one.

    Could you try using tribe_get_events() , and check if that makes a difference. It’s a neat little helper function that makes it easy to retrieve event data.

    Let me know how it goes.

    Thread Starter squasher

    (@squasher)

    Hi Darian,

    Thanks, this works! I will dive in it a bit deeper to see how I can get meta data like ACF-fields.

    Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom wp_query with tribe_events’ is closed to new replies.