Display list even if meta_key is empty


#1

Hi,

I have this issue on my $arg code where meta_key does not display if there is no value (empty) . My question is how do I display data even if my custom field is empty. Can anyone help me on this?

$args = array( 
   'post_type' => 'property', 
   'meta_key' => 'property_price',
   'orderby' => 'meta_value_num', 
   'order' => 'DESC', 
   'posts_per_page' => 10, 
   'paged' => $paged
);

thanks


#2

Just wondering, if the field is empty, what would you need to list?


#3

The current situation is a property won’t list if “price” field is empty. What I want to achieve is display property both empty or not.


#4

I think what you’re trying is to display the property with highest price in the order and also display property with no price as well, right?

$args = array(
'post_type' => 'property'
'posts_per_page' => 10, 
'paged' =>  $paged,
'orderby' => 'meta_value_num',
'order' =>  'desc',
'meta_query' => array(
    'relation' => 'OR',
    array(
        'key'     => 'property_price',
        'value'   => '0',
        'compare' => '>=',
    ),
)

);

I think this could help. try it once


#5

thanks but this still not working.