Advanced WP_Query with meta_query, orderby?

You should really read the documentation on meta_query‘s

Here is what is allowed in a meta_query

  • key (string) – Custom field key.

  • value (string|array) – Custom field value. It can be an array only when compare is 'IN', 'NOT IN', 'BETWEEN', or 'NOT BETWEEN'. You don’t have to specify a value when using the 'EXISTS' or 'NOT EXISTS' comparisons in WordPress 3.9 and up.

    (Note: Due to bug #23268, value is required for NOT EXISTS comparisons to work correctly prior to 3.9. You must supply some string for the value parameter. An empty string or NULL will NOT work. However, any other string will do the trick and will NOT show up in your SQL when using NOT EXISTS. Need inspiration? How about ‘bug #23268’.)

  • compare (string) – Operator to test. Possible values are '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'EXISTS' and 'NOT EXISTS'. Default value is '='.

  • type (string) – Custom field type. Possible values are 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'. Default value is 'CHAR'.

Your ordering needs to take place outside your meta_query. You can try the following

$args = [
    'post_type'      => ['page', 'news-articles', 'about-articles', 'involved-articles'],
    'posts_per_page' => 4,
    'meta_key'       => 'home_order',
    'orderby'        => 'meta_value_num',
    'meta_query'     => [
        [
            'key'      => 'home_page',
            'value'    => 'yes',
        ]
    ],
];

Additional notes:

  • As from PHP 5.4 you can use short array syntax, ie, you can use [] instead of array(). If you still running any version before PHP 5.6, you should seriously consider upgrading.

  • showposts is dropped in favor of posts_per_page, so rather use posts_per_page