title: order by custom field include even if empty - wordpress
body: <p>I have a query for a page of posts. </p>
  
  <p>It return results based on a custom post type, and custom field value. Now I've added the ability to order the results based on another custom field.</p>
  
  <pre><code>$loop = new WP_Query( array ( 'post_type' =&gt; 'new', 'orderby' =&gt; 'meta_value_num', 'meta_key' =&gt; 'over-length', 'meta_query' =&gt; array( array( 'key' =&gt; 'over-make', 'value' =&gt; 'Doral', 'compare' =&gt; 'LIKE') ) ) );
  </code></pre>
  
  <p>I've run into a bit of a problem. I'm ordering the results by a custom field called 'over-length' but it seems that if a post doesn't contain a value for 'over-length' it is excluded from the results.</p>
  
  <p>I'm wondering how could I change my code so that it included post that don't have a value for orderby.</p>
  
  <p>Also just thought of a workaround, but not sure how to do it. I'm using a plugin called "more fields" to create my custom fields. Would it be easier to check if the 'over-length' field is empty and set it to 0? if so how do I go about doing this.</p>
  
  <p><em>Update</em></p>
  
  <p>I've looked into the issue a bit further. It seems that if no value is given to 'over-length' the custom field is not added to wp_postmeta in the database. If I give a post a over-length value then go back and remove it it does in fact include the result in my query as the field still exist in the database. So how can I get this custom field to be entered into the database if it has a value or not?</p>