• Resolved Howdy_McGee

    (@howdy_mcgee)


    Hello,

    I’m trying to add a custom meta query to my shop. Whenever I do, the Advanced Labels disappear completely. Why does this happens and how could I go about fixing it? Here’s the custom meta query I’m working with:

    add_action( 'pre_get_posts', function( $query ) {
    
    	if( is_admin() ) {
    		return;
    	}
    
    	if( isset( $_GET, $_GET['in_stock'] ) ) {
    
    		$meta_query = (array)$query->get( 'meta_query', array() );
    		$meta_query[] = array(
    			array(
    				'key'		=> '_stock_status',
    				'value'		=> 'instock',
    			),
    		);
    		$query->set( 'meta_query', $meta_query );
    
    	}
    
    } );
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hi,

    It is strange indeed.

    Please tell me – what WordPress theme you are currently using? Also – what exactly page you want to modify – is it a shop page or maybe search results page?

    Regards

    Thread Starter Howdy_McGee

    (@howdy_mcgee)

    @mihail-barinov Thanks for the quick reply! We’re trying to modify all shop pages so that if the in_stock $_GET key is found, it only shows products that are in-stock. We have a button in place to add/remove the query string on click.

    I’m able to replicate this issue on a fairly vanilla install with just WooCommerce (7.4.1) and Advanced Woo Labels (1.62). We’re using Storefront (4.2.0) with PHP 8.0.14. Everything appears up to date.

    Thread Starter Howdy_McGee

    (@howdy_mcgee)

    The issue was that I was missing a $query->is_main_query() check. The hook above was interfering with this plugins get_posts() call.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Label Disappears with Custom Meta Query’ is closed to new replies.