WordPress WP_Query orderby being overwritten

$args = array( ‘post_type’ => ‘mcm_company’, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ‘posts_per_page’ => ‘1000’, ‘post_status’ => ‘publish’, ); $r = array(); $the_query = new WP_Query( $args ); I’m expected to see the results get returned in alphabetical order, but it’s not. The final query is [request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 … Read more

WP_Query with tax_query, order by most ‘matches’

TL;DR: How can I sort a WP_Query based on how many ‘matches’ there are on the tax_query set. Furthermore, how can I then add more posts if the posts_per_page is not met due to the tax_query added? Full story: Hi all, I’m fairly new to WP_Query editing, therefore this question. I’ve checked out multiple posts … Read more

Change default ordering of taxonomy terms – pre_get_terms

I wanted to change the default taxonomy terms order by its ‘term_order’ value instead of ‘name’ in admin side. So I tried something like below. But it doesn’t work and php memory exhaust. function uc_order_term( $wp_query ) { $wp_query->query( array( ‘taxonomy’ => ‘category’, ‘orderby’ => ‘term_order’, ‘order’ => ‘ASC’ ) ); } add_action( ‘pre_get_terms’, ‘uc_order_term’); … Read more

Meta query with order by another custom field

Edit: I will try to explain in detail my problem. I am working on a portfolio site. There are a few custom post types: Projects, Publications, Exhibitions, Lectures and Slides. Home page consists of following sections: slider with Slides portfolio consisting of: selected (marked by Client) Projects, Publications, Exhibitions and Lectures and remaining Projects, Publications, … Read more

Define orderby in url

is there a way to set the order of posts via the url? /orderby/date/order/desc/ i have tried several things with add_rewrite_rule whiteout success. add_action( ‘init’, ‘wpse13483_init’ ); function wpse13483_init() { add_rewrite_rule( ‘category/(.+?)/orderby/([^/]+)/order/([^/]+)(/page/?([0-9]{1,}))?/?$’, ‘index.php?category_name=$matches[1]&paged=$matches[5]&orderby=$matches[2]&order=$matches[3]’, ‘top’ ); } best, Dan. 2 Answers 2 adding this in the functions.php file works. Just remember to re-save your permalinks & … Read more