BuddyDev

Search

[Resolved] Search in a list of media

  • Participant
    Level: Initiated
    Posts: 9
    Francoise on #8953

    Hello
    First of all, this a great plugin. I have try to understand all the possibility and read lot of topic in this support forum but i’m not a developper and i try to learn on my own.

    So, i’d like to add a search form on a page where all the media are listed.

    I have try this :
    In the backoffice add a simple page and put on, this two shortcode :

    [wpbsearch]

    [mpp-list-media view=list]

    on my functions.php i have add this code for the search shortcode :

    add_shortcode(‘wpbsearch’, ‘get_search_form’);

    and this code (you post here :https://buddydev.com/support/forums/topic/searching-and-re-ordering-within-a-gallery/ ) :

    function mpp_custom_use_search_args( $args ) {

    //assuming your search form has input element ‘search-terms’
    if ( isset( $_REQUEST[‘search-terms’] ) ) {
    $args[‘search-terms’] = $_REQUEST[‘search-terms’];
    }
    //Using ‘search-terms’ in args allows us to search usign MPP_media_Query
    //$args[‘search-terms’]

    return $args;

    }
    add_filter( ‘mpp_main_media_query_args’, ‘mpp_custom_use_search_args’ );

    When i try a search, it doesn’t works.

    I think the probleme become from the search form ? Maybe ?

    Thanks for your help.

    Françoise

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #8954

    Hello

    Welcome to buddydev. Please use the following code in your functions.php file and remove or comment the old code. Please me know if it works or not.

    
    function buddydev_get_search_form() {
    
    	?>
    	<form method="post">
    		<label>
    			<input name="bd-search-media" type="text" placeholder="search media">
    		</label>
    		<input type="submit" value="Search">
    	</form>
    	<?php
    }
    add_shortcode('wpbsearch', 'buddydev_get_search_form');
    
    function mpp_custom_use_search_args( $atts ) {
    
    	//assuming your search form has input element 'search-terms'
    	if ( isset( $_REQUEST['bd-search-media'] ) ) {
    		$atts['search_terms'] = $_REQUEST['bd-search-media'];
    	}
    
    	return $atts;
    
    }
    add_filter( 'mpp_shortcode_list_media_query_args', 'mpp_custom_use_search_args' );
    
    

    Thank You
    Ravi

  • Participant
    Level: Initiated
    Posts: 9
    Francoise on #8983

    Hello Ravi,

    This works perfectly 🙂
    I’m really happy.
    Thanks à lot for all your help.

    Françoise

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #8984

    You are welcome.

    Regards
    Ravi

The topic ‘ [Resolved] Search in a list of media’ is closed to new replies.

This topic is: resolved