-
AuthorPosts
-
May 23, 2022 at 9:49 am #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
May 23, 2022 at 11:39 am #1352615Hey 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,
IsmaelMay 31, 2022 at 11:02 am #1353564Hi 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.
June 1, 2022 at 6:12 am #1353682Hi,
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,
IsmaelJune 1, 2022 at 10:36 am #1353705Hi 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.
June 1, 2022 at 2:58 pm #1353768Hi,
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,
IsmaelJune 2, 2022 at 9:27 am #1353881HI 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.
June 4, 2022 at 3:29 am #1354098Hi,
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,
IsmaelJune 7, 2022 at 8:07 am #1354351Hello Ismael,
We have the maintenance mode off and here send you the login.
Thanks advance.
BR,Antonio.
June 8, 2022 at 5:06 am #1354472Hi,
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,
IsmaelJune 8, 2022 at 7:35 am #1354480Hi 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.
June 10, 2022 at 1:15 pm #1354808Hi,
Could you see it?
Thanks advance!BR,
Antonio
June 13, 2022 at 1:43 am #1355007Hi,
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,
IsmaelJune 13, 2022 at 8:48 am #1355012Hi 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.
June 21, 2022 at 11:00 am #1355970Hi,
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,
IsmaelJune 24, 2022 at 2:30 pm #1356406Hi Ismael,
Thank you!
I will wait for news about this.
Will you reply here?Thanks advance,
BR,
Antonio
June 28, 2022 at 9:07 am #1356680Hi,
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,
IsmaelJuly 4, 2022 at 9:18 am #1357174Hi Ismael,
OK, Thank you!
BR,
Antonio.
-
AuthorPosts
- You must be logged in to reply to this topic.