$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wp query - How to filter on placeholder image|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp query - How to filter on placeholder image

matteradmin10PV0评论

I'm using the woocommerce-auto-category-thumbnails plugin to replace a blank category thumbnail with a random thumbnail from one of the products in the category (or child categories).

It is supposed not to use the thumbnail if the products have no thumbnails, using this query

   $query_args = array(
        'post_status' => 'publish',
        'post_type' => 'product',
        'posts_per_page' => 1,
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'field' => 'id',
                'taxonomy' => 'product_cat',
                'terms' => $cat->term_id
            ),
            array(
                'field' => 'slug',
                'taxonomy' => 'product_visibility',
                'terms' => 'exclude-from-catalog',
                'operator' => 'NOT IN',
            ),
            array(
                'key' => '_thumbnail_id',
                'value' => '',
                'compare' => '!='
            )
        )
    );

to select products in the category.

However, the last term,

            array(
                'key' => '_thumbnail_id',
                'value' => '',
                'compare' => '!='
            )

have no effect, I've even tried

            array(
                'key' => '_thumbnail_id',
                'value' => '234',
                'compare' => '=='
            ) 

and I still get random images, sometimes the placeholder.

The query is being run, because if I change the $cat->term_id to a constant, I get images from the same category all the time.

I guess I could fetch more products and loop until I found one with a real image, but I find that rather wasteful.

Is it possible to fix the query to do what's wanted?

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far