Order posts by custom column using pre_get_posts

I found out the answer myself. There are other filters that let you adjust the query before it’s run: http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_clauses The posts_clauses filter runs before the query gets executed and is essentially the sum of all filters that run immediately before it. Apart from posts_clauses, there are several more precise filters that modify only a … Read more

Want to order by Meta Values (tweaking Post Order Widget)

Because price is not a post table column (I’m assuming it’s a post meta field), you need to extend the query & order by meta_value_num instead: case ‘title’: if ( ! $meta_query = $vars->get( ‘meta_query’ ) ) $meta_query = array(); $meta_query[] = array( ‘compare’ => ‘!=’, ‘value’ => ”, ‘key’ => ‘price’, /* This should … Read more

Using orderby with 2 meta keys

One of the options would be to sort at a database level by a dynamically calculated column. This is too complex for me. Having your task on production I would probably create a third meta key: ‘division’ derivated from the two and update its value on every post save. Then I would sort by this … Read more

User list order by user meta

The QA that you have linked to is related but not needed here. meta_value_num is still not part of the user_query core and so, your meta_value_num parameter has no effect on the query. Just use meta_value as described on codex and you’ll get what you want.

Custome column sort by date not title

After a lot of guess work and research I’ve managed to come up with a simple solution. function column_orderby( $vars ) { $vars[‘orderby’] = ‘date’; $vars[‘order’] = ‘desc’; return $vars; } add_filter( ‘request’, ‘column_orderby’ ); This will sort all of the columns by ‘date’ as well as order them by ‘desc’! Hope it helps anyone … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)