• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Including a custom post type element in search results

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Including a custom post type element in search results

This topic is: resolved

Tagged: customize search results

  • This topic has 1 reply, 2 voices, and was last updated 7 years ago by Victor Font.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • May 28, 2019 at 9:27 am #491376
    timburkart
    Member

    Hello!

    I just added the code below to my child theme's functions.php and I guess it works because it does return the CPT text I was looking for. However my search results no longer include the excerpt text that it did before. What did I do to remove that?

    Also, I would like to know how I can modify my CPT snippet to return 2 CPT data items, each on a separate line.

    Thank you!

    add_action( 'pre_get_posts', 'modify_search_results' );
    
    To view the site, please use the password "hellothere" and then go to the Explore by Keyword page and select a keyword to search on.
    
    function modify_search_results( $query ) {
    
    	if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
            add_filter( 'the_content', 'custom_field_content' );
        }
        return $query;
    }
    
    function custom_field_content( $content ) {
    
        $field = '<p class="source-type">' . genesis_get_custom_field( 'source_type' ) . '</p>';
    
    	$output = genesis_get_custom_field( 'source_type' ) ? $field : $content;
    
    	return $output;
    
    }
    
    http://gmoresearch.org
    May 28, 2019 at 2:11 pm #491384
    Victor Font
    Moderator

    You replaced the $content with the custom field rather than adding the field to the content.

    What you might want to try is this:

    $output = $content . "<br>" . genesis_get_custom_field( 'source_type' ) ? $field : $content;


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Including a custom post type element in search results’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble