Home › Forums › Pro Support › Better search results with wp show posts
Tagged: search results
- This topic has 6 replies, 3 voices, and was last updated 2 years, 11 months ago by
Tom.
-
AuthorPosts
-
October 19, 2020 at 11:12 am #21368
Klaus
ParticipantI 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.
October 20, 2020 at 2:11 pm #21434Tom
KeymasterHi there,
This may be possible with some custom PHP.
Just to confirm, are you using GeneratePress?
October 23, 2020 at 2:42 pm #21556Klaus
ParticipantYes of course GP Theme, GPpremium, Wpshowpostspro, Generateblocks, Simple css. Everything there.
October 24, 2020 at 1:57 pm #21592Klaus
ParticipantThe website is https://honigwerk.de
October 26, 2020 at 2:15 pm #21649Tom
KeymasterWe 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.
October 29, 2020 at 3:59 am #21870Michal
ParticipantHi, 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; } );
October 29, 2020 at 2:06 pm #21912Tom
KeymasterSorry about that – can you try the updated code?: https://wpshowposts.com/support/topic/better-search-results-with-wp-show-posts/#post-21649
-
AuthorPosts
- You must be logged in to reply to this topic.