-
AuthorPosts
-
August 3, 2024 at 12:12 am #1463682
Hi,
I managed removing portfolio from search, but not woocommerce products.
Can you share function code.Thank you.
X.August 3, 2024 at 10:41 am #1463688can you post your code snippet that you used on portfolio?
a portfolio is nothing else than a custom post type as woocommerce products too.i only do know that there is an include snippet – all posttypes that are not listet ( as: product ) are then excluded
function exclude_from_search($query) { if ( !$query->is_admin && $query->is_search) { // include the posttype that should be included to search results $query->set('post_type', array('page', 'post', 'portfolio') ); } return $query; } add_filter( 'pre_get_posts', 'exclude_from_search' );
if you do not like the portfolios – just remove it from array
btw. the ajax search has its own query ! If you like to influence this too …
August 3, 2024 at 10:39 pm #1463738Hi,
Thank you for getting back to me.
I need the same code for products – which I don’t want to be included in search.
For portfolio I use
add_filter(‘avf_portfolio_cpt_args’, ‘avf_portfolio_cpt_args_mod’);
function avf_portfolio_cpt_args_mod($args) {
$args[‘exclude_from_search’] = true;
return $args;
}Tahnk you.
August 3, 2024 at 11:41 pm #1463740August 3, 2024 at 11:46 pm #1463741Hi,
I want to use the menu search
And on the page, a hidden search on wide scree.
I don’t want to buy a plugin. There must be a way to remove wooconmerce products for search.
Thank you.August 4, 2024 at 8:51 am #1463745thanks: didn’t know about that extra filter in portfolio registration
did you try
for ajax search ( thats the menu search) :function avf_ajax_search_query_mod( $search_parameters ){ $defaults = array( 'numberposts' => 5, 'post_type' => array( 'page', 'post' ), 'post_status' => 'publish', 'post_password' => '', 'suppress_filters' => false ); $_REQUEST['s'] = apply_filters( 'get_search_query', $_REQUEST['s']); $search_parameters = array_merge( $defaults, $_REQUEST ); return $search_parameters; } add_filter('avf_ajax_search_query', 'avf_ajax_search_query_mod', 10, 1);
and in addition for search resultspage :
function post_types_for_search_results($query) { if ( !$query->is_admin && $query->is_search) { $query->set('post_type', array('page','post') ); $query->set('post_status', array( 'publish' ) ); } return $query; } add_filter( 'pre_get_posts', 'post_types_for_search_results' );
In this case, your code snippet would be unnecessary.
btw: because of new cpt support in enfold – there is a similar filter for any other cpt: avf_custom_elements_cpt_args – maybe it is possible to use it for specific post-types ( portfolio, product, etc. to have that analog to your code snippet.August 4, 2024 at 8:53 am #1463746Thank you but I need to hide products from search.
Thank youy
August 4, 2024 at 9:16 am #1463749Yes and the snippets above do only allow to show pages and posts ( so if product is not in that array – it will not be shown)
the first is for having only posts and pages in that ajax search ( that is the menu search icon )
i can not test it because i got no page at the moment with woocommerce .
But with Portfolio it works this way.August 4, 2024 at 7:50 pm #1463791Guenni007,
You are a star…thank you so much.August 4, 2024 at 10:03 pm #1463798 -
AuthorPosts
- You must be logged in to reply to this topic.