Skip to:
Content
Pages
Categories
Search
Top
Bottom

Best Way to Change Search Form


  • carlsandburg
    Participant

    @carlsandburg

    wordpress 3.8.1
    buddypress 1.9.2

    the BuddyPress Search form doesn’t work so well for my site since it consists mostly of pages, not posts. It only seems to search members or posts. pages don’t show….

    http://stevelescure.net/wp/

    I found the code in my theme that seems to invoke the BuddyPress version of the search function (below). I think that’s what it’s doing anyway.

    I’m thinking that i could modify the code below to do the “else” section regardless (do the regular search, not the buddpress version). I could copy the searchform.php to my child theme, edit the code, and that should (I think) do it.

    Finally, my question. How would somebody that really knows what they are doing – i’m more of an advanced beginner – make this change? Am I approaching this problem correctly? I don’t want to add any weird code to my site.

    <!– searchform.php –>
    <?php

    global $blog_id;

    // if this is the main BuddyPress-enabled blog…
    if (

    function_exists( ‘bp_search_form_type_select’ ) AND
    BP_ROOT_BLOG == $blog_id

    ) {

    // —————————————————————————–
    // BuddyPress
    // —————————————————————————–

    ?><form action=”<?php echo bp_search_form_action() ?>” method=”post” id=”search-form”>
    <label for=”search-terms” class=”accessibly-hidden”><?php _e( ‘Search for:’, ‘commentpress-core’ ); ?></label>
    <input type=”text” id=”search-terms” name=”search-terms” value=”<?php echo isset( $_REQUEST[‘s’] ) ? esc_attr( $_REQUEST[‘s’] ) : ”; ?>” />

    <?php echo bp_search_form_type_select() ?>

    <input type=”submit” name=”search-submit” id=”search-submit” value=”<?php _e( ‘Search’, ‘commentpress-core’ ) ?>” />

    <?php wp_nonce_field( ‘bp_search_form’ ) ?>

    </form><!– #search-form –>

    <?php

    } else {

    // —————————————————————————–
    // WordPress
    // —————————————————————————–

    ?><form method=”get” id=”searchform” action=”<?php echo site_url(); ?>/”>

    <label for=”s”><?php _e(‘Search for:’, ‘commentpress-core’); ?></label>

    <input type=”text” value=”<?php the_search_query(); ?>” name=”s” id=”s” />

    <input type=”submit” id=”searchsubmit” value=”<?php _e( ‘Search’, ‘commentpress-core’ ); ?>” />

    </form>

    <?php

    }

    ?>

Viewing 1 replies (of 1 total)

  • Richie KS
    Participant

    @rkcorp

    try filter only page search, add this to child functions

    if( !function_exists( 'only_page_search_filter' )):
    function only_page_search_filter($query) {
    if ($query->is_search) { $query->set('post_type', 'page'); }
    return $query;
    }
    add_filter('pre_get_posts','only_page_search_filter');
    endif;
Viewing 1 replies (of 1 total)
  • The topic ‘Best Way to Change Search Form’ is closed to new replies.
Skip to toolbar