Home Forums Basel support forum Hidden or Catalog products showing in Search results

Hidden or Catalog products showing in Search results

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #6500

    miguel1876
    Participant

    Hi there

    I have a specific products in a Category (samples) that I need to exclude from the ajax search results. I have those Catalog Visibility set to “Catalog” only, however they still show in the ajax search results. Also setting them to “Hidden” which I prefer, does work either. They still show in results. I have also tried different bits of code and nothing seems to work, including:

    
    /* Exclude a Category from Search Results */
    
        add_filter( 'pre_get_posts' , 'search_exc_cats' );
        function search_exc_cats( $query ) {
    
        if( $query->is_admin )
        return $query;
    
        if( $query->is_search ) {
        $query->set( 'category__not_in' , array( 224 ) ); // Cat ID
        }
        return $query;
        }

    Can you please help?

    Thanks

    #6502

    miguel1876
    Participant

    Please note … I have have this code on there to show 16 results instead of the default :

    // Ajax Search Results
    
    function basel_header_block_search() {
    $header_search = basel_get_opt( 'header_search' );
    ?>
    <div class="search-button basel-search-<?php echo esc_attr( $header_search ); ?>">
    	<a href="#">
    		<i class="fa fa-search"></i>
    	</a>
    	<div class="basel-search-wrapper">
    		<div class="basel-search-inner">
    			<span class="basel-close-search"><?php esc_html_e('close', 'basel'); ?></span>
    			<?php basel_header_block_search_extended( false, true, array('thumbnail' => 1, 'price' => 1, 'count' => 16), false ); ?>
    		</div>
    	</div>
    </div>
    <?php
    }
    #6505

    Artem Temos
    Keymaster

    Hello,

    Thank you for contacting us.

    As we can understand the problem is only in AJAX search? Samples are not shown when you hit “Enter”?

    Regards

    #6508

    miguel1876
    Participant

    Hi.

    No, that is not the problem.
    The problem is that Samples ARE showing in the search results.

    Example… enter “firm skin” in the search, and you will see this product:
    “Sample: Firm Skin Acai Booser Serum 0.10/oz”
    This product Catalog visibility is set to Hidden so it should not show in the results.

    Thanks

    #6511

    Artem Temos
    Keymaster

    Yes, we understand. But when you hit enter and see the search results page, is this product shown there also?

    #6516

    miguel1876
    Participant

    That is fine. The product page is no problem.
    My client just does not want the samples to show in the search results.

    #6517

    Artem Temos
    Keymaster

    Ok, we will try to reproduce the problem on our development environment and will back to you soon.

    Thank you

    #6519

    miguel1876
    Participant

    Thank you very much. 🙂

    #6530

    Artem Temos
    Keymaster

    Hello,

    This bug will be fixed in our next update. For now you can change the following code in basel/inc/classes/Search.php file

    		$query_args = array(
    			'posts_per_page' => 3,
    			'post_status'    => 'publish',
    			'post_type'      => 'product',
    			'no_found_rows'  => 1,
    			//'order'          => $order,
    			'meta_query'     => array()
    		);

    with this one

    		$query_args = array(
    			'posts_per_page' => 3,
    			'post_status'    => 'publish',
    			'post_type'      => 'product',
    			'no_found_rows'  => 1,
    			//'order'          => $order,
                'meta_query' => array(
                    array(
                        'key' => '_visibility',
                        'value' => array('visible', 'search'),
                        'compare' => 'IN'
                    )
                )
    		);

    It should fix your problem.

    Kind Regards

    #6541

    miguel1876
    Participant

    Hi there

    The code worked perfectly.
    Thank you so much for your quick help 🙂

    Cheers

    #6547

    Artem Temos
    Keymaster

    Great, you are welcome 🙂

Viewing 11 posts - 1 through 11 (of 11 total)

The topic ‘Hidden or Catalog products showing in Search results’ is closed to new replies.