Viewing 18 posts - 1 through 18 (of 18 total)
  • Author
    Posts
  • #1352608

    Hello!

    I have include a search than find in portfolio items. I have two types of categories. I would need the search only find results in one type of category. How can I do it?
    Many thanks,

    BR,

    Antonio

    #1352615

    Hey Antonio,

    Thank you for the inquiry.

    How did you add the search form? You should be able to adjust the default search query by using the pre_get_posts filter. If you are using the AJAX search from the theme, using the get_search_query filter from the functions-enfold.php file > avia_ajax_search function should work.

    This documentation should help.

    // https://developer.wordpress.org/reference/classes/wp_query/#category-parameters

    Best regards,
    Ismael

    #1353564

    Hi Ismael,

    I’m using the regular enfold search filter/personalice/portfolio items
    It is medical web and in the portfolio items we have “doctors” category or “types of cancer” category. The idea is the search en doctor page only find doctos and the search of types of cancer only find types of cancer. Could you explain what we have to do? Sorry, maybe is difficult to me.
    Thanks advance,

    BR,

    Antonio.

    #1353682

    Hi,

    Thank you for the clarification.

    To adjust the query for the default AJAX search field, try to use this filter in the functions.php file.

    
    function avf_modify_ajax_search_query($search_parameters) {
    	if ( is_admin() ) return;
    
        parse_str($search_parameters, $params);
    
        if( is_page('tipos-de-cancer') ) {
    		$params['post_type'] = 'portfolio_entries';
            $params['tax_query'] = array(
                array(
                    'taxonomy' => 'portfolio_entries',
                    'terms'    => 'cancers',
                ),
            );	
    	}
    
        if( is_page('doctors') ) {
    		$params['post_type'] = 'portfolio_entries';
            $params['tax_query'] = array(
                array(
                    'taxonomy' => 'portfolio_entries',
                    'terms'    => 'doctors',
                ),
            );
    	}
    
        $search_parameters = http_build_query($params);
    
    	return $search_parameters;
    }
    
    add_filter('avf_ajax_search_query', 'avf_modify_ajax_search_query', 10, 1);
    

    Make sure to replace the values in the following lines with the actual names of the portfolio categories.

    'terms'    => 'cancers',
    

    ====== AND ======

    'terms'    => 'doctors',
    

    You may need to adjust or use the actual name of the “doctors” page in this line.

    if( is_page('doctors') ) {
    

    Best regards,
    Ismael

    #1353705

    Hi Ismael,

    Many thanks for your answer!

    I have add this in functions.php but it not works:

    ////////////////////////////////////

    function avf_modify_ajax_search_query($search_parameters) {
    if ( is_admin() ) return;

    parse_str($search_parameters, $params);

    if( is_page(‘tipos-de-cancer’) ) {
    $params[‘post_type’] = ‘portfolio_entries’;
    $params[‘tax_query’] = array(
    array(
    ‘taxonomy’ => ‘portfolio_entries’,
    ‘terms’ => ‘tipo-de-cancer’,
    ),
    );
    }

    if( is_page(‘nuestro-equipo’) ) {
    $params[‘post_type’] = ‘portfolio_entries’;
    $params[‘tax_query’] = array(
    array(
    ‘taxonomy’ => ‘portfolio_entries’,
    ‘terms’ => ‘medico’,
    ),
    );
    }

    $search_parameters = http_build_query($params);

    return $search_parameters;
    }

    add_filter(‘avf_ajax_search_query’, ‘avf_modify_ajax_search_query’, 10, 1);

    ////////////////////////////////////

    Thank you,

    BR,

    Antonio.

    #1353768

    Hi,

    Sorry about that. The post type should be set to portfolio and not portfolio_entries. Please look for these lines..

    $params['post_type'] = 'portfolio_entries';
    

    .. and replace it with:

    $params['post_type'] = 'portfolio';
    

    Best regards,
    Ismael

    #1353881

    HI Ismael,

    Many thanks for your effort but do not works. Now this is the code:

    ////////////////////////////

    function avf_modify_ajax_search_query($search_parameters) {
    if ( is_admin() ) return;

    parse_str($search_parameters, $params);

    if( is_page(‘tipos-de-cancer’) ) {
    $params[‘post_type’] = ‘portfolio’;
    $params[‘tax_query’] = array(
    array(
    ‘taxonomy’ => ‘portfolio_entries’,
    ‘terms’ => ‘tipo-de-cancer’,
    ),
    );
    }

    if( is_page(‘nuestro-equipo’) ) {
    $params[‘post_type’] = ‘portfolio’;
    $params[‘tax_query’] = array(
    array(
    ‘taxonomy’ => ‘portfolio_entries’,
    ‘terms’ => ‘medico’,
    ),
    );
    }

    $search_parameters = http_build_query($params);

    return $search_parameters;
    }

    add_filter(‘avf_ajax_search_query’, ‘avf_modify_ajax_search_query’, 10, 1);

    ////////////////////////////

    Many thanks,

    BR,

    Antonio.

    #1354098

    Hi,

    Thank you for following up.

    The site is currently on maintenance mode, so we were not able to check the search field. Please post the login details in the private field and make sure that the Appearance > Theme File Editor is accessible so that we can test the modification properly.

    Best regards,
    Ismael

    #1354351

    Hello Ismael,

    We have the maintenance mode off and here send you the login.
    Thanks advance.
    BR,

    Antonio.

    #1354472

    Hi,

    Thank you for the info.

    We adjusted the code in the functions.php file but it doesn’t seem to be taking effect. Is there some kind of server or hosting cache for the site?

    Please include the FTP login details in the private field so that we can edit the files properly. This is the adjusted code in the functions.php file.

    
    function ava_search_filter_get_posts($query) {
        $terms = is_page( 110 ) ? 13 : 12;
    
        if ( ! $query->is_search ) return $query;
    
        $tax_query = $query->get( 'tax_query' ) ? : array();
    
        $tax_query[] = array(
            'taxonomy' => 'portfolio_entries',
            'terms'    => $terms,
        );
    
        $query->set( 'tax_query', $tax_query );
    }
    add_action( 'pre_get_posts', 'ava_search_filter_get_posts' );
    

    Best regards,
    Ismael

    #1354480

    Hi Ismael,

    I have include the code but look doesn’t works. Here I send you the FTP loging.
    We have a lot of sites is the 95mctest.es folder.
    Thanks advance!

    BR,

    Antonio.

    #1354808

    Hi,

    Could you see it?
    Thanks advance!

    BR,

    Antonio

    #1355007

    Hi,

    Sorry for the delay. We adjusted the pre_get_posts action hook in the functions.php file, and it seems to be working as expected. Only items that belong to the current category page are being returned in the search field. (see private field)

    Best regards,
    Ismael

    #1355012

    Hi Ismael,

    Many thank for your answer!
    Works perfect in cancers, but it do not work in doctors.

    And we create another search in the service page that have the filter only in pages but it not works too.

    Could you help me?

    Thanks advance,

    BR.

    Antonio.

    #1355970

    Hi,

    Sorry for the delay. Looks like it is not possible to check for the current page in a pre_get_posts hook, so what you are asking may not be possible. I will forward the issue to our channel, see if there’s anything else we can do about this.

    This is the current code in the functions.php file.

    
    function ava_search_filter_get_posts($query) {	
        if ( ! $query->is_search ) return $query;
    
        $terms = 12;
    
        if ( ! is_admin()                                               
             && 'nuestro-equipo' === $query->get( 'pagename' ) 
        ) {
    		$terms = 13;
    	} 
    
        $tax_query = $query->get( 'tax_query' ) ? : array();
    
        $tax_query[] = array(
            'taxonomy' => 'portfolio_entries',
            'terms'    => $terms,
        );
    
        $query->set( 'post_type', 'portfolio' );
        $query->set( 'tax_query', $tax_query );
    }
    add_action( 'pre_get_posts', 'ava_search_filter_get_posts' );
    

    Best regards,
    Ismael

    #1356406

    Hi Ismael,

    Thank you!
    I will wait for news about this.
    Will you reply here?

    Thanks advance,

    BR,

    Antonio

    #1356680

    Hi,

    We are still not able to find a solution for this, unfortunately, You may need to look for another search plugin or a custom script. We listed a few that might work.

    // https://wordpress.org/plugins/ajax-search-lite/
    // https://wordpress.org/plugins/search-filter/

    Best regards,
    Ismael

    #1357174

    Hi Ismael,

    OK, Thank you!

    BR,

    Antonio.

Viewing 18 posts - 1 through 18 (of 18 total)
  • You must be logged in to reply to this topic.