• Resolved mowar

    (@mowar)


    Hi! One of our customers uses Events Calendar, and I’m trying to ask down the events by using get_posts, and the ordering has to be based on a meta_key. The meta_key ordering does not work, because some code from your plugin overwrites the query. I tried to use tribe_suppress_query_filters to avoid the issue, but that did not work. Example:

    $args = array(
    'post_type' => 'tribe_events',
    'posts_per_page' => 5,
    'meta_key' => '_edit_last',
    'orderby' => 'meta_value_num',
    'order' => 'ASC',
    );

    add_filter('tribe_suppress_query_filters', function(){ return true; });
    $events = get_posts($args);

    foreach($events AS $event){
    var_dump(get_post_meta($event->ID, '_edit_last', true));
    }

    The ordering doesn’t works with tribe_events post type, but it does with other post types. Result at our customer:

    string(2) "12"
    string(2) "16"
    string(2) "14"
    string(1) "1"
    string(1) "1"

    Could you tell me why, or is this a bug?

    Some additional info from the debugging:
    If I check the last query after get_posts:

    $events = get_posts($args);
    global $wpdb;
    var_dump($wpdb->last_query);

    then it will be this:

    string(104) "SELECT *
    FROM
    [prefix]_tec_occurrences
    WHERE (occurrence_id IN (827,834,862,863,866))
    LIMIT 50
    OFFSET 0"

    What I would expect:

    string(209) "SELECT [prefix]_posts.ID FROM [prefix]_posts WHERE ...."

    So I don’t want any Events Calendar queries or query modifications to run, only get_posts in its native state.

    • This topic was modified 7 months, 3 weeks ago by mowar.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support tristan083

    (@tristan083)

    Hi @mowar ,

    Thank you for reaching out.

    Code customization is outside our scope of support, but, I did some digging around and another user asked a similar question. One of our developers provided this bit of code, which might help sort things out for you:

    public function suppress_query_filters( $query_args ): array {
    /**
    * Checks if the 'tribe_events' post type is present in the query arguments.
    * If not, it returns the query arguments unmodified.
    */
    if ( ! in_array( Tribe__Events__Main::POSTTYPE, (array) $query_args['post_type'], true ) ) {
    return $query_args;
    }

    // Set the 'tribe_suppress_query_filters' to true.
    $query_args['tribe_suppress_query_filters'] = true;

    // Remove the 'eventDisplay' argument if present to include past events.
    if ( isset( $query_args['eventDisplay'] ) && 'upcoming' === $query_args['eventDisplay'] ) {
    unset( $query_args['eventDisplay'] );
    }

    return $query_args;
    }
    Plugin Support Darian

    (@d0153)

    Hi there,

    It appears that we haven’t heard back from you in a while, so I’ll assume that the matter has been resolved. If you need any more help, feel free to start a new thread and we’ll be happy to assist you.

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

The topic ‘tribe_suppress_query_filters doesn’t work’ is closed to new replies.