SHARE
TWEET

Untitled

a guest Jun 16th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_action('pre_get_posts', function ($query) {
  2.      if ('my_post_type' === $query->get('post_type')) {
  3.           $query->set('meta_query', array(
  4.               'relation'     => 'OR',
  5.               'sort_empty'   => array('key' => 'order', 'compare' => 'NOT EXISTS'),
  6.               'sort_numbers' => array('key' => 'order', 'compare' => 'EXISTS')
  7.           ));
  8.           $query->set('orderby', 'meta_value_num');
  9.           $query->set('order', 'ASC');
  10.      }
  11.  });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top