Custom Fields On Search Results Page

This tutorial provides 2 solutions which enable you to display custom fields on your search results page in Genesis.

Solution 1

This solution uses a search.php file in your child themes root directory.

Solution 2

This solution uses a conditional tag is_search from your child themes functions.php file.

add_action( 'genesis_entry_content', 'custom_fields_search_page', 12 );
function custom_fields_search_page() {

<pre><code>if ( ! is_search() ) {
    return;
}

$value = get_post_meta( get_the_ID(), 'custom', true );

if ( ! empty( $value ) ) {

echo '&lt;div class="your-class"&gt;'. $value .'&lt;/div&gt;';

}
</code></pre>

}

Assumes your custom field name ( key ) is custom.

Uses the genesis_entry_content hook with a 3rd parameter of 12

Related Code Snippets

Was This Tutorial Helpful?

Free

$0

Access only to all free tutorials per month.



Monthly

$75

Access to 10 premium tutorials per month.


Tutorial Request


Includes code guarantee and coding support.

Yearly

$500

Access to 15 premium tutorials per month.


Monthly Tutorial Request


Includes code guarantee and priority coding support.