NO BUG: PHP Query Editor? Can you set is main query with args?

PHP Query Editor? Can you set is main query with args?

I need to use my custom query args, but I also need is main query on, but this option is not available for custom query.

No info on this forum? Using filters that filter my woo categories, if I use default with main query on, then filters properly select on the category pages, but breaks when you use the php query editor. Not compatible?

This seems to work in the query editor. What a pain.

// Get the current product category (if any)
$current_category = get_queried_object();

$custom_query = array(
    'post_type'      => 'product',
    'post_status'    => 'publish',
    'posts_per_page' => 24,
    // Retain your custom product type filter:
    'tax_query'      => array(
        'relation' => 'AND', // Ensure both queries are met
        // Existing product type query:
        array(
            'taxonomy' => 'product_type',
            'field'    => 'slug',
            'terms'    => array('simple', 'variable', 'grouped'),
            'operator' => 'IN',
        ),
    ),
    'meta_query'     => array(
        array(
            'key'     => '_variation_id',
            'compare' => 'NOT EXISTS',
        ),
        array(
            'key'     => '_children',
            'compare' => 'NOT EXISTS',
        ),
    ),
    'orderby'        => 'menu_order',
    'order'          => 'ASC',
    //'relevanssi'     => true,
);

// If we're on a product category page, add the current category filter.
if ( is_tax( 'product_cat' ) && $current_category ) {
    $custom_query['tax_query'][] = array(
        'taxonomy' => 'product_cat',
        'field'    => 'slug',
        'terms'    => $current_category->slug,
    );
}

return $custom_query;

Hi dailce,
Thanks so much for your report!

Enable the “is main query” toggle first and then the PHP query editor. It stays enabled even if it’s no longer visible. You can also disable the query editor toggle, enable the “is main query” toggle, and re-enable the query editor.

The settings stay as long as you don’t change the query type.

Best regards,
timmse