V
V
Vladislav2021-11-09 14:24:13
WordPress
Vladislav, 2021-11-09 14:24:13

How to display products with photos?

There is an online store on WordPress (WooCommerce). The question arose of how to make it so that the catalog first displays products with an image, and only then without it. Maybe someone faced such a problem. Help me please)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2021-11-11
@wppanda5

Add this condition through the pre_get_posts filter for the store page and product archives

'order' => 'DESC', 
        'orderby'   => 'meta_value_num',
        'meta_query' => [
            [
                'relation' => 'OR', 
                array(
                    'key' => '_thumbnail_id', 
                    'compare' => 'NOT EXISTS' 
                ],
                [
                     'key' => '_thumbnail_id', 
                     'compare' => '!NOT EXISTS' 
                ]
            ]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question