Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to override core template function

  • @skeary

    Participant

    I want to change the bp_directory_groups_search_form() function in bp-groups-template.php to change how the search form displays.

    What’s the best way to do this in my theme? I would put something in my theme’s functions.php but not sure best way to do this.

Viewing 7 replies - 1 through 7 (of 7 total)
  • @hnla

    Participant

    It and the others now have filters so you can filter in to the function bp-groups-template.php approx line: 2496.

    Out of interest what did you want to change about the form?

    @skeary

    Participant

    Oh sweet.. is the filter tag same as the function name?

    I need to make the button say ‘Go’ instead of ‘Search’ to match a comp.

    @aces

    Participant

    @megainfo

    Participant

    Hi @Skeary,

    There is no filter for bp_directory_groups_search_form(), You can change create a new custom function and replace the old call of bp_directory_groups_search_form by the new function.

    
    function bp_custom_directory_groups_search_form() {
    
    	$default_search_value = bp_get_search_default_text( 'groups' );
    	$search_value         = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value; ?>
    
    	<form action="" method="get" id="search-groups-form">
    		<label><input type="text" name="s" id="groups_search" placeholder="<?php echo esc_attr( $search_value ) ?>" /></label>
    		<input type="submit" id="groups_search_submit" name="groups_search_submit" value="<?php _e( 'Go', 'buddypress' ) ?>" />
    	</form>
    
    <?php
    }
    

    The other solution is by javascript, you can change the text of the button by this code :

    
    jQuery('#groups_search_submit).attr('value','Go');
    
    

    @hnla

    Participant

    @megainfo Actually you’re quite correct… well almost, there are filters and they were committed but think the commit was rolled back as I found a few issues and the updates didn’t make it into 1.8.1 but check your trunk files you’ll see them there.


    @skeary
    Apologies I was ahead of myself there, next release will contain them; for the moment follow Aces advice or megainfos new function to replace.

    @biswadip

    Participant

    I put the bp_custom_directory_groups_search_form() function suggested by @meginfo into my functions file.

    But when I call it from a template it only works if I submit it to the members directory like this

    function bp_custom_directory_members_search_form() {
    
    	$default_search_value = bp_get_search_default_text( 'members' );
    	$search_value         = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value; ?>
    
           <form action="<?php echo site_url() ?>/members/" method="get" id="search-members-form">
    		<label><input type="text" name="s" id="members_search" placeholder="<?php echo esc_attr( $search_value ) ?>" /></label>
    		<input type="submit" id="members_search_submit" name="members_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
    	</form>
    <?php
    }

    If I try to submit to the same page like this:

    form action=""

    of if I try and submit it to the full path of the file I get a 404 not found message.

    How should I submit the function in order to have it give me the search results on the page I want?

    Thanks

    @biswadip

    Participant

    Sorry I put my customised members search function above instead of the groups search but essentially I have the same problem with both the members and the groups search.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to override core template function’ is closed to new replies.
Skip to toolbar