• 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

Custom search.php template for Genesis Framework

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 › General Genesis Framework Discussions › Custom search.php template for Genesis Framework

This topic is: not resolved
  • This topic has 0 replies, 1 voice, and was last updated 1 year, 3 months ago by annahernandez99.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • March 11, 2021 at 8:49 am #503420
    annahernandez99
    Participant

    I have setup a custom search.php template within the Genesis Framework and I've created an array variable for specific post types:

    $post_types = array('treatment','post', 'team_member' );

    However, I need to edit which fields are pulled in for each of the arrays as two out of three are custom post types built with ACF Pro (one is the default WP posts).

    Please find the most up to date code below. Ideally, I want to set the number of posts that appear for the three arrays ('treatment','post', 'team_member' ) and what fields are pulled in.

    <?php
    add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );

    /* Remove the default loop */
    remove_action( 'genesis_loop', 'genesis_do_loop' );
    add_action( 'genesis_loop', 'hs_do_search_loop' );
    add_action( 'genesis_before_loop', 'genesis_do_search_title' );

    /**
    * Echo the title with the search term.
    *
    * @since 1.9.0
    */
    function genesis_do_search_title() {

    $title = sprintf( '%s %s', apply_filters( 'genesis_search_title_text', __( 'Search Results for:', 'genesis' ) ), get_search_query() );

    echo apply_filters( 'genesis_search_title_output', $title ) . "\n";

    }

    /**
    * Outputs a custom loop
    *
    * @global mixed $paged current page number if paginated
    * @return void
    */
    function hs_do_search_loop() {
    // create an array variable with specific post types in your desired order
    $post_types = array('treatment','post', 'team_member' ); // other custom post type can be added.
    echo '<div class="search-content">';
    foreach ( $post_types as $post_type ) {
    // get the search term entered by user
    $s = isset( $_GET["s"] ) ? $_GET["s"] : "";
    // accepts any wp_query args
    $args = (array(
    's' => $s,
    'post_type' => $post_type,
    'posts_per_page' => 4,
    'order' => 'ASC'
    ));
    switch ( $post_type ) {
    case 'treatment':
    $post_type_heading = 'Treatments';
    break;

    case 'post':
    $post_type_heading = 'Latest News';
    break;

    case 'team_member':
    $post_type_heading = 'Consultants';
    break;
    }
    echo '<div class="post-type '. $post_type .'"><div class="post-type-heading">'. $post_type_heading . '</div>';
    // force content limit.
    add_filter( 'genesis_pre_get_option_content_archive_limit', 'sk_content_limit' );
    // modify the Content Limit read more link.
    add_filter( 'get_the_content_more_link', 'sp_read_more_link' );
    // remove archive pagination.
    remove_action( 'genesis_after_endwhile', 'genesis_posts_nav' );
    // custom genesis loop with the above query parameters and hooks.
    genesis_custom_loop( $args );
    echo '</div>';
    }
    }
    echo '</div>'; // .search-content
    function sk_content_limit() {
    return '150'; // number of characters.
    }
    function sp_read_more_link() {
    return '... Read more';
    }
    function sk_show_excerpts() {
    return 'excerpts';
    }
    genesis();

  • Author
    Posts
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
Log In

CTA

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

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2022 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