Black Friday sale! Get 25% off WPSP Pro! Discount automatically applied at checkout.

[Support request] Better search results with wp show posts

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Better search results with wp show posts

  • This topic has 6 replies, 3 voices, and was last updated 4 weeks ago by Tom.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #21368
    Klaus
    Participant

    I would like to show my search results in the way I show my wp show posts category pages. Can I create a search results page with wp show posts? At the moment search results display a little ugly.

    #21434
    Tom
    Keymaster

    Hi there,

    This may be possible with some custom PHP.

    Just to confirm, are you using GeneratePress?

    #21556
    Klaus
    Participant

    Yes of course GP Theme, GPpremium, Wpshowpostspro, Generateblocks, Simple css. Everything there.

    #21592
    Klaus
    Participant

    The website is https://honigwerk.de

    #21649
    Tom
    Keymaster

    We could try something like this:

    First, upload the dev version of WPSP: https://wpshowposts.com/wp-show-posts-1-2-0/

    Then, add this PHP:

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

    Then just update 123 with the ID of your list.

    Not 100% sure it will work, but worth a try.

    #21870
    Michal
    Participant

    Hi, not working for me, on GeneratePress (not premium). I am trying to insert this with code snippets plugin and i see this message

    Don’t Panic

    The code snippet you are trying to save produced a fatal error on line 9:
    syntax error, unexpected ‘;’, expecting ‘)’

    The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.

    Please use the back button in your browser to return to the previous page and try to fix the code error. If you prefer, you can close this page and discard the changes you just made. No changes will be made to this site.

    I could “rapair” this issue with this change in the code but the web displays broken.

    add_action( 'generate_before_main_content', function() {
        if ( is_search() ) {
            wpsp_display( 2232 );
        }
    } );
    
    add_filter( 'wpsp_query_args', function( $query, $settings ) {
        if ( 2232 === (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;
    } );
    • This reply was modified 4 weeks ago by Michal.
    #21912
    Tom
    Keymaster
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.