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

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.