-
BenchmarkGraphics
Hello,
I have created a new development website for a client, using GeneratePress Pro and GenerateBlocks Pro: staging.simplyecoltd.co.uk
I have followed the instructions from your knowledge base for setting up a search results page, but I can’t get a page based on my archive page to work as my search results page, with a page heading that displays ‘Search results: keyword’.
Would you be able to let me know what I am doing wrong please? To log in, please use the details I have provided.
Thanks,
Mark
-
Hi Mark,
I have followed the instructions from your knowledge base for setting up a search results page
It seems you are using a query loop block as the loop template for the search result page.
but I can’t get a page based on my archive page to work as my search results page, with a page heading that displays ‘Search results: keyword’.
Not sure what this means, do you just want to add the ‘Search results: keyword’ to your search results page?
Let me know!
-
BenchmarkGraphics
Hi Ying,
Thanks for your reply.
It seems you are using a query loop block as the loop template for the search result page.
That is correct. Is that the right thing to do, if I want my search results to match my archive page?
do you just want to add the ‘Search results: keyword’ to your search results page?
Yes, I’d like ‘Search results: keyword’ to replace the heading. Would you be able to help me please?
Thanks,
Mark
-
That is correct. Is that the right thing to do, if I want my search results to match my archive page?
That’s correct, but it seems no matter what I search, the resulting posts are the same.
So make sure you’ve ticked theinherit loop from template boxin the loop template.
https://docs.generatepress.com/article/block-element-loop-template/Yes, I’d like ‘Search results: keyword’ to replace the heading. Would you be able to help me please
1. Create a new block element – page hero for the search result page only.
2. Add an H1 headline block with the content:
Search results: search query, and add an additional CSS class to the H1 headline block, eg.search-query, here’s a screenshot for your reference:
https://www.screencast.com/t/hZ8g0PMiz9IZ3. Add this PHP snippet to replace the static text “search query” with the actual dynamic search query.
add_filter( 'render_block', function( $block_content, $block ) { if ( ! empty( $block['attrs']['className'] ) && 'search-query' === $block['attrs']['className'] && is_search() ) { $search_query = get_search_query(); $block_content = str_replace('search query', $search_query, $block_content); } return $block_content; }, 10, 2 );Adding PHP: https://docs.generatepress.com/article/adding-php/
-
BenchmarkGraphics
Thank you Ying, I have followed your instructions and it is now how I intended it to be. Apart from the search results includes pages as well as posts. How can I make it posts only?
Also, I’ve attempted to create a ‘Nothing Found’ no search results template: https://puu.sh/JE8uc/a95caa5f32.png
Would you also be able to tell me how I can remove the default ‘Nothing Found’ information below my page hero.
Thanks,
Mark
-
To only show posts on the search result page is more of a question for WordPress.
However the solution is not very complicated, so try this PHP code:
function search_filter($query) { if ($query->is_search && !is_admin()) { $query->set('post_type', 'post'); } return $query; } add_filter('pre_get_posts','search_filter');For the 404 page template, please raise a new topic, it’s easier for us to categorize and should be more efficient for other users who’s looking for an answer 🙂 Thanks for your understanding!
-
BenchmarkGraphics
Thank you Ying for all your help.
As requested, I have created a new topic for removing the default ‘Nothing Found’ functions for the no search results found template: https://generate.support/topic/remove-default-nothing-found-information/#post-1586
-
You are welcome 🙂
It seems the new topic has been resolved by my colleagues.
- You must be logged in to reply to this topic.