We're merging with GenerateBlocks! Learn more here.

[Support request] Search Results page

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Search Results page

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #36705
    Gloria
    Participant

    Hello everyone.
    I am using WP Show Post together with Elementor PRO.
    On the search results page I want to use WPSP, but I can’t.
    How should I prepare the query for it to work?
    Thanks

    #36707
    Fernando
    Participant

    Hi Gloria,

    Linking Search results to a WP Show Post List isn’t possible.

    If you wish to exclude categories in your search results page, you would need a custom code like this: https://wordpress.stackexchange.com/questions/162232/exclude-categories-from-search-query#:~:text=1-,Answer,-Active

    Also see for how to get the Category ID: https://share.getcloudapp.com/7KuQ1KKG

    You may add this code through a plugin like Code Snippets.

    Hope this clarifies! 🙂

    #36710
    Gloria
    Participant

    Thank you for your reply.

    The aim was to have uniformity in the graphics on the search results page as well.

    If it is not possible to do this, I will use Elementor’s default settings.

    #36712
    Fernando
    Participant

    Though it is not possible through WPSP functionalities, we can add a PHP code like this to effectively link the Search Results page to a WPSP List:

    add_action( 'generate_before_main_content', function() {
        if ( is_search() ) {
            wpsp_display( 1362 );
        }
    } );
    
    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
        if ( 1362  === (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;
    } ); 

    Tested this on my test website just now and it’s working. Kindly replace 1362 with the WPSP list ID.

    You may add this custom PHP code through a plugin like Code Snippets.

    Hope this helps! 🙂

    • This reply was modified 6 months, 4 weeks ago by Fernando.
    #36719
    Gloria
    Participant

    Hi Fernando, thanks for your reply.
    Unfortunately I’m using the Hello theme, so ‘generate_before_main_content’ and ‘generate_has_default_loop’ don’t work for me.

    Can you help me anyway?

    #36727
    Fernando
    Participant

    I see. If that’s the case, if you’re using a child them, what you can do is manually remove the default loop in the search template file, and replace manually run the shortcode of the WPSP list.

    Example of an edited template-parts/search.php file in Hello theme:

    <?php
    /**
     * The template for displaying search results.
     *
     * @package HelloElementor
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly.
    }
    ?>
    <main id="content" class="site-main" role="main">
    	<?php 
    	add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
        if ( 1362  === (int) $settings['list_id'] ) {
            $args['s'] = esc_html( $_GET['s'] );
        }
    
        return $args;
    },20,2 );
    	if ( apply_filters( 'hello_elementor_page_title', true ) ) : ?>
    		<header class="page-header">
    			<h1 class="entry-title">
    				<?php esc_html_e( 'Search results for: ', 'hello-elementor' ); ?>
    				<span><?php echo get_search_query(); ?></span>
    			</h1>
    		</header>
    	<?php endif; ?>
    	<div class="page-content">
    		<?php 
    		echo do_shortcode('[wp_show_posts id="1362"]');
    		 ?>
    	</div>
    
    	<?php wp_link_pages(); ?>
    
    	<?php
    	global $wp_query;
    	if ( $wp_query->max_num_pages > 1 ) :
    		?>
    		<nav class="pagination" role="navigation">
    			<?php /* Translators: HTML arrow */ ?>
    			<div class="nav-previous"><?php next_posts_link( sprintf( __( '%s older', 'hello-elementor' ), '<span class="meta-nav">&larr;</span>' ) ); ?></div>
    			<?php /* Translators: HTML arrow */ ?>
    			<div class="nav-next"><?php previous_posts_link( sprintf( __( 'newer %s', 'hello-elementor' ), '<span class="meta-nav">&rarr;</span>' ) ); ?></div>
    		</nav>
    	<?php endif; ?>
    </main>

    As shown, I ran/added this filter:

    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
        if ( 1362  === (int) $settings['list_id'] ) {
            $args['s'] = esc_html( $_GET['s'] );
        }
    
        return $args;
    },20,2 );

    and manually ran the shortcode of the WPSP list with:

    echo do_shortcode('[wp_show_posts id="1362"]');

    Kindly replace 1362 with the list’s ID.

    Tested this with Hello Theme and it seems to be working.

    Hope this clarifies. 🙂

    #36733
    Gloria
    Participant

    Thank you very much for your reply.
    I will try as soon as possible.

    #36735
    Fernando
    Participant

    You’re welcome Gloria! Hope it works! Feel free to reach out anytime if you’ll need assistance with anything else. 🙂

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