Merge 2 args in one WP_Query and order it by date

A better approach could be using three queries. First two query retrieve the post ids, and third one query post by ids. // first query $first_ids = get_posts( array( ‘fields’ => ‘ids’, ‘posts_per_page’ => ’10’, ‘post_status’ => ‘publish’, ‘post_type’ => array(‘news’,’partners’), ‘orderby’ => ‘date’, ‘order’ => ‘DESC’ )); // second query $second_ids = get_posts( array( … Read more

Order posts by tags count?

As @Robert hue says you can’t do it directly, you need a filter and a CASE in the orderby eg $args1 = array ( ‘orderby’ => ‘tag_count’, ‘order’ => ‘DESC’, ‘post_type’ => ‘post’, ‘pagination’ => true, ‘posts_per_page’ => ‘1’, // 1 post per page?! ‘meta_key’ => ‘_thumbnail_id’, ‘suppress_filters’ => false, ); function wpse173949_posts_clauses( $pieces, $query … Read more

Is there a way to do multiple ordering on a multiple meta_query?

As of WordPress 3.4.1, there is no way, out of the box, to order by multiple meta values. Since we can’t do it cleanly, we’ll have to hack something together. We can hook into posts_orderby to manually modify the ordering. It’s not altogether pretty, but it will get the job done. Here’s an example: add_filter(‘posts_orderby’, … Read more

Order Posts by Closest Numeric Values

One possibility is a direct SQL query similar to the one given here. But I’m not convinced that it would be much more efficient than 2 queries, all handled by WordPress: The is untested $price =0; //Price of current property $id=0; //Property (post) ID. $args = array( ‘post_type’ => ‘property’, ‘post__not_in’=>array($id), ‘posts_per_page’=> 2, ‘meta_query’ => … Read more

Move admin menu at the end

The global variable $menu can be manipulated. Here, we are moving the Pages menu item to the end: Maybe there’s a simpler method to do the recursive array search, I’ve grabbed an example from PHP Manual. The value to be searched has to be inspected inside the $menu var, enable the debug lines to brute … Read more

How can I set a default listing order on the admin page for a custom taxonomy? (without plugins)

You need to take a look at /core_root/wp-admin/includes/class-wp-terms-list-table.php and then add an extended class and make use of the WP_list_Table Class and documentation. basically you’re overriding the order and orderby in some custom plugin. Btw: “No Plugins” is never a good idea as plugins may show you how it works in code and therefore be … Read more

Trying to perform complex custom field query with order by set to field value

If the value of your custom fields is numeric, you could try ordering with meta_value_num. Also note that both meta_value and meta_value_num require meta_key in the query as described here. $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => $number, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘meta_key’ => ‘event-start’, ‘value’ => $today_is, ‘type’ => ‘NUMERIC’, … Read more

WP_Query sort by comment meta data

I solved my problem by adding a hook on the action wp_insert_comment. When my hook is called i calculate the average rating for each rating meta-tag of my comments. Then i add a meta tag to the post with the result I can use the post meta-tag to sort with wp-query

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