Forums Forums Search & Filter Pro Multiple loops on one page

Viewing 10 posts - 1 through 10 (of 11 total)
  • Anonymous
    #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,
    Neil

    Trevor
    #68991

    Well, 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
    #69000

    Ok 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;
    Trevor
    #69004

    Was the WP_Query line in there before? Without the argument in the brackets I mean.

    Anonymous
    #69006

    This 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

    Trevor
    #69010

    Try this:

    $query = new WP_Query(
    	array( 
    		'author__in' => $ids,
    		's' => $_GET['s'],
    		'search_filter_id' => 110
    	)
    );
    Anonymous
    #69014

    Very 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
    #69016

    No no, my mistake – this seems to be working correctly!

    I’ll just do some more bug testing, there’s something squiffy going on but maybe unrelated

    Trevor
    #69023

    OK, let me know how you get on and if I can close the thread?

    Anonymous
    #69031

    Yes 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

Viewing 10 posts - 1 through 10 (of 11 total)