[Support request] Using WPSP with Search and Filter Pro

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Using WPSP with Search and Filter Pro

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #34481
    Nicolas
    Participant

    Hello,

    My question is a bit complex and it may not be possible to easily do what I want.

    Today I use the plugin Search and filter Pro to display posts according to tags.

    These posts are displayed with The Grid plugin (a plugin similar to WPSP).

    For example here is a search on the “Rock” posts: https://hautlescours.fr/recherche/?_sft_pratiques=rock. Posts are filtered with Search and Filter Pro and displayed with The Grid.

    To do that, Search and filter Pro uses a custom archive.php template which I modified to “call” The Grid. Search and filter Pro indicates that “Templates must use the The Loop and not a custom query”.

    Here is the code of the custom archive.php template I use. The important part is the line The_Grid('Posts_archive', true); // where true is for template mode that makes it possible to display the filtered posts using The Grid plugin.

    <?php
    /**
     * The template for displaying Archive pages.
     *
     * @package GeneratePress
     */
    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly.
    }
    get_header(); ?>
    	<div id="primary" <?php generate_do_element_classes( 'content' ); ?>>
    		<main id="main" <?php generate_do_element_classes( 'main' ); ?>>
    			<header class="page-header">
    			<h1 class="page-title">Résultats de la recherche</h1>
    			</header>		
    			<?php	
    			do_action( 'generate_before_main_content' );
    			/*if ( generate_has_default_loop() )*/ {
    			
    			The_Grid('Posts_archive', true); // where true is for template mode	
    		
    }
    			/**
    			 * generate_after_main_content hook.
    			 *
    			 * @since 0.1
    			 */
    			do_action( 'generate_after_main_content' );			
    			?>	
    		</main>
    	</div>
    	<?php
    	/**
    	 * generate_after_primary_content_area hook.
    	 *
    	 * @since 2.0
    	 */
    	do_action( 'generate_after_primary_content_area' );
    	generate_construct_sidebars();
    	get_footer();

    I tried to do something similar with WPSP using the line if ( function_exists( 'wpsp_display' ) ) wpsp_display( 78685 ); instead of The_Grid('Posts_archive', true); but unfortunately it displays all the posts and not only the filtered posts (posts with the tag “Rock” in my example hereabove).

    Bottom line: I would like to use WPSP with Search Filter Pro given that WPSP doesn’t have a filter/search function

    What are your views on that? I understand this question is difficult and relates to a third-party plugin.
    Best,
    Nicolas

    #34501
    elvin
    Moderator

    Hi there,

    The wpsp_query_args filter part of Tom’s reply here would help.

    https://wpshowposts.com/support/topic/better-search-results-with-wp-show-posts/#post-21649

    but you’ll need the beta version to make the wpsp_query_args work.

    #34509
    Nicolas
    Participant

    Thank you Elvin,

    I installed WPSP 1.2.0-alpha.3 along with WPSP Pro 1.0.0 and added Tom’s snippet to my functions.php file but unfortunately the snippet breaks my site: http://hautlescours.fr.dedivirt248.your-server.de/?s=test

    Best,

    Nicolas

    #34539
    elvin
    Moderator

    Can you share the exact snippet you’ve tried to apply?

    #34565
    Nicolas
    Participant

    Hello, this is the snippet:

    add_action( 'generate_before_main_content', function() {
        if ( is_search() ) {
            wpsp_display( 78685 );
        }
    } );
    
    add_filter( 'wpsp_query_args', function( $query, $settings ) {
        if ( 78685 === (int) $settings['list_id'] ) {
            $query->set( 's', esc_html( $_GET['s'] ) );
        }
    
        return $query;
    } );
    
    add_filter( 'generate_has_default_loop', function( $has_loop ) {
        if ( is_search() ) {
            return false;
        }
    
        return $has_loop;
    } );
    #34600
    elvin
    Moderator

    Can you make this change in your wp-show-posts.php file? https://github.com/tomusborne/wp-show-posts/commit/286caf1164db8b6b6f38b85d3a011b519a27f4de

    And then use this PHP snippet:

    add_action( 'generate_before_main_content', function() {
        if ( is_search() ) {
            wpsp_display( 78685  );
        }
    } );
    
    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
        if ( 78685  === (int) $settings['list_id'] ) {
            $args['s'] = esc_html( $_GET['s'] );
        }
    
        return $args;
    },20,2 );
    
    add_filter( 'generate_has_default_loop', function( $has_loop ) {
        if ( is_search() ) {
            return false;
        }
    
        return $has_loop;
    } ); 
    #34615
    Nicolas
    Participant

    Thank you Elvin,

    I didn’t have to touch anything in wp-show-posts.php.

    Your new snippet works well for the regular search page. Here is for example the results for the word “huissiers”, WPSP is used correctly to display the results: http://hautlescours.fr.dedivirt248.your-server.de/?s=huissiers

    Unfortunately such is not the case when I search/filter results through Search and Filter Pro (here on the same search “huissiers”): http://hautlescours.fr.dedivirt248.your-server.de/?sfid=32129&_sf_s=huissiers

    But I think I’d rather ask Search and Filter Pro support for help as the bulk of the functionality I want is on their side.

    Best.

    #34632
    elvin
    Moderator

    I see.

    Yeah I’m not exactly sure how that plugin does its search query.

    My code was based from the default way WordPress does its search query and I assumed Search and Filter pro does the same. You may have to ask the plugin developer how they do their search and maybe show my snippet if they can recommend modification to it. 😀

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.