Order by empty custom field

I order my posts by custom field faq-order. That’s work for me:

$faqArgs = array(
‘post_type’ => ‘faq’,
‘meta_key’ => ‘faq-order’,
‘order’ => ‘ASC’,
‘orderby’ => ‘meta_value_num’,

$faq = new WP_Query($faqArgs);

But post disappear from result response if those field faq-order is empty. How can I fix it? How can I use default value (for example 0), if that field is empty?

Read more here:: Order by empty custom field

Leave a Reply

Your email address will not be published. Required fields are marked *