BuddyDev

Search

[Resolved] Create activity search form

  • Participant
    Level: Initiated
    Posts: 8
    sunny buddy on #52337

    Hi buddydev

    The default search form doesn’t display
    on my buddypress or theme.

    members and group pages have there own
    search forms , but there is nothing for activity.

    I looked at some of your older plugs.

    –bp searchable activity–
    That applies to a universal form with dropdown
    that isn’t there.

    –global unified search– discontinued
    it wouldn’t create a buddypress search page option..

    Do you have some theme functions code that will put
    a search form on the activity page ?

    Or that could create a search page with a short code ?

    Thank you

    sunnybuddy

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #52341

    Hello Sunnybuddy,

    Welcome to the BuddyDev forums. Please let me know which theme or BuddyPress template pack you are using so that I can help. Also, let me know if you are using Youzify yes or no.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 8
    sunny buddy on #52355

    Hello Ravi

    Well, both buddypress and theme are old ,
    legacy templet pack, the theme is full width primer.

    The theme has been heavily modified and runs on a
    large child sheet activated by theme functions code.

    buddypress is pre-Nouveau with a lot of plugs and
    theme function tweeks. There are core file mods for
    small things like number of posts or members
    per page.

    The theme is responsive / adjust to mobile
    devices. It might be better to some how create a
    short-code search page because I don’t know
    what a search form will do to the responsive
    activity page.

    No Youzify

    Anything you can think of would be greatly
    appreciated.

    Thanks
    Sunnybuddy.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #52358

    Hello Sunnybuddy,

    Thank you for the acknowledgement. As you said you are using the older BuddyPress which is why there is no activity search form in the latest version you can find it on the Activity directory page. But to check whether activity search is supported on your setup just try to add “?s=text-to-search” with the URL on the directory page and check whether it shows results or not. If it shows the expected result you can create a search form using HTML and make it searchable.

    Please give it a try.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 8
    sunny buddy on #52380

    Works !
    Your great Ravi

    Example URL

    https://buddypresssite.com/activity/?s=dogs-and-cats

    Is there an easy php that will create the same search
    form thats on the groups / members page?
    because that would work with the responsive theme !

    If not,

    If html is used on a new WP page to create the form,
    were and how are the posts rendered ?

    either way I can’t write that code.
    could you help with that?

    Thank you
    sunnybuddy

    • This reply was modified 8 months, 1 week ago by sunny buddy.
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #52401

    Hello Sunny,

    Thank you for the acknowledgment. Please place the following code in the “bp-custom.php” file or your active theme “functions.php” file.

    
    add_shortcode( 'bp-activity-search-form', function ( $atts ) {
    
    	if ( ! function_exists( 'bp_get_activity_directory_permalink' ) ) {
    		return '';
    	}
    
    	$atts = shortcode_atts(
    		array(
    			'label'     => __( 'Search Activities', 'bp-custom' ),
    			'btn_label' => __( 'Search', 'bp-custom' ),
    		),
    		$atts
    	);
    
    	ob_start();
    
    	?>
    	<div class="bp-activity-search-form">
    		<?php if ( $atts['label'] ) : ?>
    			<h4><?php echo esc_html( $atts['label'] ); ?></h4>
    		<?php endif; ?>
    		<form action="<?php echo esc_url( bp_get_activity_directory_permalink() ); ?>" method="get">
    			<input type="text" name="s">
    			<input type="submit" class="button" value="<?php echo esc_attr( $atts['btn_label'] ); ?>">
    		</form>
    	</div>
    	<?php
    
    	return ob_get_clean();
    } );
    
    

    Please use the shortcode “[bp-activity-search-form]”. It only works with the activity directory page. Please give it a try and let me know.

    To more info on “bp-custom.php” check here: https://buddydev.com/docs/buddypress-guides/what-is-bp-custom-php/

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 8
    sunny buddy on #52432

    Hey Ravi

    That code works ! ! ! Thank You. Thanks again ! !

    I tried the shortcode on the WP page created for the
    buddypress activity page. the form doesn’t appear
    on the activity page.

    So I made a new WP page. The short code works
    there and forwards to the activity page with the
    results.

    Can the search form appear on the
    activity page somehow ?
    If it was on top of the other content and
    pushed it down on the page the resposive
    theme would work.
    Can code be transferred from a newer
    buddypress and applied to a legacy
    buddypress?

    Sunnybuddy

  • Participant
    Level: Initiated
    Posts: 8
    sunny buddy on #52433

    HI ravi

    Maybe an easy way to put the search form only
    on the activity page would be to use the WP
    header.

    This worked but the form appears on every
    page

    <?php
    echo do_shortcode(‘[bp-activity-search-form]’); ?>

    This will keep a shortcode function on the homepage

    <?php
    echo do_shortcode(“[bp-activity-search-form restrict_to=home]”);
    ?>

    Could you help me specify a page ID number ?

    I tried some things, they didn’t work.

    Thank You.
    Sunny

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #52446

    Hello Sunny,

    Thank you for the acknowledgement. You can use the ‘bp_is_activity_directory’ function to make sure it shows only on the activity directory page. Please give it a try.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 8
    sunny buddy on #52457

    Hi Ravi

    Thanks for all your great help !

    Tried this , didn’t work

    <?php
    echo do_shortcode(‘[bp_is_activity_directory]’); ?>

    Changed theme functions code from

    this

    add_shortcode( ‘bp-activity-search-form’, function ( $atts ) {

    to this

    add_shortcode( ‘bp_is_activity_directory’, function ( $atts ) {

    —————–

    Then used shortcode

    <?php
    echo do_shortcode(‘[bp_is_activity_directory]’); ?>

    —————–

    That made the form but didn’t restrict it to the Activity Page.

    That’s all I can do.

    How do I use this ?

    ‘bp_is_activity_directory’ function

    Thank you
    Sunny

The topic ‘ [Resolved] Create activity search form’ is closed to new replies.

This topic is: resolved