0

I'm trying to list a few post sorting by a custom field value ("space-comments"). It's working very well, however, when the custom field is empty the loop don't get this post.

Any idea to fix it? Thanks :)

            $args = array( 
                'post_type' => 'spaces',
                'post_per_page' => '500',
                'meta_key' => 'space-comments',                 
                'orderby' => 'meta_value_num',                  
                'order' => 'DESC',
                'author__in' => $tradicionalIds,
                    'meta_query' => array(
                        'relation' => 'AND',                            

                        array(
                            'key' => 'space-city',
                            'value' => $search,
                            'compare' => 'LIKE'
                       ),
                        array(
                            'key' => 'space-comments',
                            'compare' => 'EXISTS',                              
                        ),          

                    )
                );



            $query = new WP_query($args);
0

I found an other post on stackexchange that seems to answer your question:

Order by optional meta key?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.