Forums › Forums › Search & Filter Pro › Custom display results with WP_Query that contains ‘post__in’
- This topic has 5 replies, 3 voices, and was last updated 4 years, 10 months ago by
Ross.
Viewing 6 posts - 1 through 6 (of 6 total)
-
Anonymous(Private) June 24, 2020 at 4:45 pm #249954
Hello, I’m trying to implement filtering on set array of posts defined in WP_Query parameters. The WP_Query works (the right posts show up) without Search & Filter Pro, but when I add it into the mix, the WP_Query displays ALL ‘posts’ not the posts defined in the ‘posts__in’ array. Am I missing something? Thanks in advance for your time.
$favposts = $user->simplefavorites[0]['posts']; // $favposts returns as: // Array ( [0] => 201 [1] => 194 [2] => 196 [3] => 191 [4] => 199 [5] => 202 ) $args = array( 'post_type' => 'post', 'post__in' => $favposts ); $args['search_filter_id'] = 377; $query = new WP_Query($args); // The Loop if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); ?><div class="card"><?php the_title(); ?></div><?php } } else { // no posts found }
Ross Moderator(Private) June 25, 2020 at 8:57 am #250014Hmmm, you could use a really late
pre_get_posts
, check what is inpost__in
, andarray_intersect
with your array?Just a theory.
In a
pre_get_posts
, you can check$query->get('search_filter_id')
to check if the query is a S&F query.Thanks
-
AuthorPosts
Viewing 6 posts - 1 through 6 (of 6 total)