Forums › Forums › Search & Filter Pro › Multiple loops on one page
Tagged: multiple loops
- This topic has 10 replies, 2 voices, and was last updated 8 years ago by Trevor.
-
Anonymous(Private) November 7, 2016 at 12:25 pm #68988
Hey there
I’ve just set up Search & Filter Pro and I’ve almost got it working how I’m after …
What I’m trying to achieve is to have two loops of posts on one page – the first loop displays posts from ‘gold’ authors and the second loop for ‘standard’ authors.
I’ve got the loops working how I want and what I want to do is filter these search results by a custom field, if the posts contain this custom field then display the posts, this is what I’m attempting to use Search & Filter Pro for.
I’ve managed to get this working correctly for the first loop but the search form just ignores the second loop
So my question is can I pass the filters to my second loop?
Hope that’s clear! Happy to share links or code if that will help my query.
Regards,
NeilTrevor(Private) November 7, 2016 at 12:48 pm #68991Well, I have done it using the theme that I normally use, so it IS possible. In the theme I use, it uses the Custom display method and then adds the search and filter id to the wp_query arguments, like this:
$args['search_filter_id'] = 16439;
where 16439 is the form ID.So, it rather depends on how you are doing it. I do not think you could do it using Ajax though, as that can only ‘refresh’ one results container. When I do it on my theme, I have to switch Ajax off if I am doing this, I think.
Anonymous(Private) November 7, 2016 at 1:12 pm #69000Ok this sounds exactly like what I’m after but I can’t quite get it to work but I think that’s because I’m implementing it incorrectly, here’s what I’ve got … I think as my WP_Query is in an array I need to set it up slightly differently?
I’m fairly certain I’ve got the form ID correct, taken from the short code for it right?
[searchandfilter id="110"]
$ids = get_users( array( 'role' => 'gold' , 'fields' => 'ID' ) ); $query = new WP_Query( $args['search_filter_id'] = 110; array( 'author__in' => $ids, 's' => $_GET['s'] ) ); // If the query has data if($query->have_posts() ) : // Post loop while ($query->have_posts() ) : // Setup post data $query->the_post(); ?> <!-- Do HTML markup and template tags here, eg. the_content(), the_title() etc.. --> <h1>Gold user- <?php the_title(); ?></h1> <?php get_template_part( 'template-parts/content', 'search' ); endwhile; // End "If the query has data" endif;
Anonymous(Private) November 7, 2016 at 1:23 pm #69006This was my original WP_Query which works just fine filtering my results by author type;
$query = new WP_Query( array( 'author__in' => $ids, 's' => $_GET['s'] ) );
I tried to add the Search & Filter ID in like this;
$query = new WP_Query( $args['search_filter_id'] = 110; array( 'author__in' => $ids, 's' => $_GET['s'] ) );
Clearly wrong as that seems to break the page! 🙂
N
Anonymous(Private) November 7, 2016 at 1:48 pm #69014Very close!
Both loops are now running and loops like they are both getting the correct filters however both lists are only displaying one post.
I’ve currently tried removing the second loop to make this page as simple as possible for debugging so now there is just one loop on this page with the query as described above but this still only returns one post on any search term I use, looks like the correct post but only one every time
What a strange little bug!
Anonymous(Private) November 7, 2016 at 2:13 pm #69031Yes this is definitely resolved – thank you! Some of the best support I’ve ever had, I will be writing you a review.
I have another bug which after a bit of testing I’m pretty sure is unrelated so I’ll try and resolve that first myself before starting another thread.
Thank you again
N
-
AuthorPosts