Display Search Term in Results Page

I am attempting to follow these instructions:

however, I cannot find search.php. Is there a comparable file I should be looking for?

Hi Justin,

Thanks for reaching out.

Our theme uses index.php for search results which internally, switches to different sub-templates. But, you’re not limited to that as you could create your own search.php.

But since you’re only adding the count of found posts, you don’t have to follow that. Instead, please follow this

But before we continue, please check these for the initial ideas
https://theme.co/apex/forum/t/customizations-best-practices/205,
https://theme.co/apex/forum/t/how-to-upload-xtheme-to-child-theme/43246/2,

Then let’s get started,

a) Copy the file _landmark-header.php from the main theme folder \wp-content\themes\x\framework\legacy\cranium\headers\views\integrity to your child theme, resulting on the same folder path. Example

\wp-content\themes\x-child\framework\legacy\cranium\headers\views\integrity\_landmark-header.php

b) Edit your child theme’s _landmark-header.php and find this block of code

  <header class="x-header-landmark x-container max width">
    <h1 class="h-landmark"><span><?php _e( 'Search Results', '__x__' ); ?></span></h1>
    <p class="p-landmark-sub"><span><?php _e( "Below you'll see everything we could locate for your search of ", '__x__' ); echo '<strong>&ldquo;'; the_search_query(); echo '&rdquo;</strong>'; ?></span></p>
  </header>

Change it to this

  <header class="x-header-landmark x-container max width">
    <h1 class="h-landmark"><span>  <?php global $wp_query; echo $wp_query->found_posts; ?><?php _e( 'Search Results Found For', '__x__' ); ?></span></h1>
    <p class="p-landmark-sub"><span><?php _e( "Below you'll see everything we could locate for your search of ", '__x__' ); echo '<strong>&ldquo;'; the_search_query(); echo '&rdquo;</strong>'; ?></span></p>
  </header>

c) Upload your edited file back to the child theme older :slight_smile:

Thanks!

I’m sorry, but that did not work. Does it matter that I have PRO and not X?

Here is my work:

Example page:
https://bullseyesurplus.com/?s=benelli

Please note that I am running FacetWP and Relevanssi.

Hi @bullseye_surplus,

The code will not work because the search page is using the custom header.

Please add the following code under functions.php file locates in your child theme instead:

add_action( 'x_after_view_header_base', 'pro_print_search_results' );
function pro_print_search_results(){
	if(is_search()){
		global $wp_query; 
		?>
		<div class="x-container max width">
		<?php echo $wp_query->found_posts; ?>
		</div>
		<?php
	}
}

Hope it helps :slight_smile:

Hello,

I inserted that code. It returns the number of products matching that name, not the search term.

Can you suggest an edit to the code?

Hi There,

Sorry for the confusion!

Please update the code to this:


add_action( 'x_after_view_header_base', 'pro_print_search_results' );
function pro_print_search_results(){
	if(is_search()){
		?>
		<div class="x-container max width">
		<?php echo get_search_query(); ?>
		</div>
		<?php
	}
}

Hope it helps :slight_smile:

That works, thank you!

You’re welcome.

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