Custom WP Query order function possible?

No, it’s not possible. You can’t actually store arrays as meta. When they’re saved they’re converted to a string, so there aren’t individual parts that you can sort by. To do this you will need to store the share numbers as their own keys.

Exclude post from wp_query based on custom field boolean

Excluding things in queries is extremely expensive, but also avoidable. What’s more, filtering posts by their post meta values is also super expensive. That query would get exponentially slower as the post count rises. Instead you can avoid this completely by telling it what you do want, not what you don’t want. So instead of … Read more

pre_user_query vs pre_get_posts

The pre_get_posts function is a simple query modifier for general “post” queries. If you’re looking to modify the SQL directly for these query I suggest using the post_clauses hook. This hook passes an array of SQL clauses such as: $sql[‘where’] and sql[‘join’] Here you can inject your own custom SQL into the specific clauses. That … Read more

Query by meta key and order by another meta key value

You can do this with a meta_query. The get_posts() function accepts everything that WP_Query accepts so it could look something like this: $orders = get_posts( array( ‘numberofposts’ => -1, ‘posts_per_page’ => -1, ‘post_type’ => ‘executive-orders’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘meta_query’ => array( ‘relation’ => ‘AND’, ‘eo_type’ => array( ‘key’ => ‘eo_type’, ‘value’ => … Read more