Home › Forums › Pro Support › Using WPSP with Search and Filter Pro
- This topic has 7 replies, 2 voices, and was last updated 1 year, 11 months ago by
elvin.
-
AuthorPosts
-
October 9, 2021 at 8:25 am #34481
Nicolas
ParticipantHello,
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 ofThe_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,
NicolasOctober 10, 2021 at 11:05 pm #34501elvin
ModeratorHi 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.October 11, 2021 at 4:11 am #34509Nicolas
ParticipantThank 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
October 12, 2021 at 5:46 pm #34539elvin
ModeratorCan you share the exact snippet you’ve tried to apply?
October 13, 2021 at 1:14 am #34565Nicolas
ParticipantHello, 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; } );
October 13, 2021 at 7:01 pm #34600elvin
ModeratorCan 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; } );
October 14, 2021 at 1:47 am #34615Nicolas
ParticipantThank 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.
October 14, 2021 at 5:54 pm #34632elvin
ModeratorI 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. 😀
-
AuthorPosts
- You must be logged in to reply to this topic.