Skip Navigation

[Resolved] wpv_filter_query_post_process returns wrong post count

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 0 replies, has 1 voice.

Last updated by poM 3 months ago.

Author
Posts
#2680827

poM

I am trying to:
Filter views query by custom field value.

add_filter( 'wpv_filter_query_post_process', 'houzez_child_custom_views_post_process_query', 10, 3 );

function houzez_child_custom_views_post_process_query($query, $view_settings, $views_id) {

if ( $views_id == 16920 || $views_id == 16903) {

if ( !empty( $query->posts ) ) {

$results_posts = array();
$all_posts = $query->posts;

foreach ($all_posts as $post) {

$add_infos = get_post_meta( $post->ID, 'wpcf-bien-infos-add', true);

if ( empty($add_infos) || $add_infos != 'Suspendu' ) {
array_push( $results_posts, $post );
}

}

$query->posts = $results_posts;
}
}
return $query;
}

Link to a page where the issue can be seen:
hidden link (login : houseimmo, pwd : 1mm0Hous5).

I expected to see:
11 posts when clicking on the 10-15 MIN link

Instead, I got:
12 posts when clicking on the 10-15 MIN link

#2680830

poM

Finally worked it out by adding the following lines :

$query->found_posts = count ($results_posts);

poM confirmed that the issue was resolved on 2024-01-31 16:40:03.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.