WP_Query orderby not working with meta_value_num and menu_order

Found an answer to this. Somehow WordPress’ own orderby isn’t fully functional when trying to order by multiple values. I solved this by changing WP_Query to SQL Query, and including second DESC after _postmeta.meta_value+0 SELECT XXX_posts.* FROM XXX_posts INNER JOIN XXX_postmeta ON (XXX_posts.ID = XXX_postmeta.post_id) WHERE 1=1 AND XXX_posts.post_type=”sidebar_element” AND (XXX_posts.post_status=”publish”) AND (XXX_postmeta.meta_key = ‘sidebar_element_meta_alignment’ … Read more

WP_Query most viewed posts, in multiple Post Types, last 30 days, excluding a specific taxonomy term

You can try: $the_query = new WP_Query( array( ‘posts_per_page’ => ‘5’, ‘v_sortby’ => ‘views’, ‘post_type’ => array( ‘post’, ‘music’, ‘videos’, ‘albums’ ), ‘tax_query’ => array( array( ‘taxonomy’ => ‘content’, ‘field’ => ‘slug’, ‘terms’ => array( ‘indy’ ), ‘operator’ => ‘NOT IN’ ) ) )); to exclude the indy term in the content taxonomy.

Wp_query: sort by PHP variable

To the best of my knowledge, you cannot sort a query by two different parameters without an additional iteration over the retrieved posts. Since that ideally should be avoided, let me suggest a different approach: How about incorporating an additional meta value “sort_date”, or the like? And then, in your saving routine, save either the … Read more

Display all posts for taxonomy term across multiple custom post types

You can do this with an array of post types and a tax query for your term. The question you linked had special requirements as only one of the post types used the taxonomy. $args = array( ‘post_type’ => array( ‘books’, ‘movies’, ‘shows’ ), ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘status’, ‘field’ … Read more