Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1463682

    Hi,
    I managed removing portfolio from search, but not woocommerce products.
    Can you share function code.

    Thank you.
    X.

    #1463688

    can 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 …

    #1463738

    Hi,
    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.

    #1463740

    Hi,
    Try disabling the Search Icon To Main Menu option

    Best regards,
    Mike

    #1463741

    Hi,
    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.

    #1463745

    thanks: 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.

    #1463746

    Thank you but I need to hide products from search.

    Thank youy

    #1463749

    Yes 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.

    #1463791

    Guenni007,
    You are a star…thank you so much.

    #1463798

    Hi,
    Glad that Guenni007 could help, thank you Guenni007, shall we close this thread then?

    Best regards,
    Mike

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