1. Home
  2. Docs
  3. Developer Guide
  4. Miscellaneous and Snippet...
  5. Add Content To Search Results Page

Add Content To Search Results Page

Sometimes you might wish to add a little content to your search results page. Because the search results page is an 'archive' page (similar to how a blog works), it's job is to display a list of posts as opposed to display content/text.

We can get around this by following the steps below:

1: Add content to the 'Search Results' page

In WordPress navigate to 'Pages' and edit the page you have assigned to be the 'Search Results Page' under 'Property Hive > Settings > General'. Enter the required text into this page.

2: Pull content into template

By default, the text you've entered won't be displayed so we need to add a couple of lines of code to achieve this as follows:

add_action( 'propertyhive_before_search_results_loop', 'ph_display_search_results_content', 1 );
function ph_display_search_results_content()
{
    $my_postid = ph_get_page_id('search_results');
    $content_post = get_post($my_postid);
    $content = $content_post->post_content;
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    echo $content;
}

After adding the above your text should appear above the search form.

Was this article helpful to you? No Yes

How can we help?