Dynamic Content: Search result term

Didn’t find something useful in the forum. How to add the search term to dynamic content?

I tried: “Search results for {{dc:query:get_search_query()}}” in a headline element of a search result layout, but that does not work.

Edit: Oh, and is there a condition for elements in case there are no search results?

best regards
Mirco

PS: great theme update which becomes better after every update :slight_smile:

Hi Mirco,

Thank you for reaching out to us. Regretfully there is no option display the search query using dynamic content however you can achieve the same result by adding the following code in your functions.php file:

// Shortcode to display search query
function display_search_query() { 
 
return get_search_query(); 
 
}
add_shortcode('search_query', 'display_search_query');

This will register a shortcode [search_query] you can use this shortcode in your search result layout to get the search query for example, you can use it like this:

Search results for [search_query]

Please note that the code provided above serves as a guide only and is to help you in getting started so implementing it and maintaining the code will be out of our support scope and for further maintenance for new possible versions of the theme that may cause the customization to break, you will need to hire a developer.

Hope this helps!

Thanks. That worked good.

How about a condition if no results have been found? Right now it’s just a blank page (with header & footer) in case there are no search results.

Somehow I achieved this by adding the following condition to a text element with the content “Your search didn’t return any results”:

Condition: Post Type | is not | Post

Dunno if that is how it is intended, but it works for my needs :slight_smile:

1 Like

Hey @mircotripoczky,

You are most welcome. It is good to know that you have resolved your issue already.
If you need anything else we can help you with, don’t hesitate to open another thread.

Cheers.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.