Order by & include array by specific post ids

use post__in key instead of include to get posts from the specific post ids. $args = array( ‘post_type’ => ‘testimonials’, ‘posts_per_page’ => 4, ‘orderby’ => ‘ID’, ‘post__in’ => array(883, 563, 568, 106), ); And to order posts by the given posts ids, you can use the following array. $args = array( ‘post_type’ => ‘testimonials’, ‘posts_per_page’ … Read more

Order tags, but not alphabetically

One way to do it is to store the order of the tags as post meta data, using the action set_object_terms which happens to pass the tags in the order they appear on edit, eg in your “functions.php”: // Called in admin on updating terms – update our order meta. add_action( ‘set_object_terms’, function ( $object_id, … Read more

alphabetically order role drop-down selection in dashboard

Almost the same approach One Trick Pony has chosen, but I am using translated names and uasort() (to preserve the keys): add_filter( ‘editable_roles’, ‘t5_sort_editable_roles’ ); /** * Array of roles. * * @wp-hook editable_roles * @param array $roles * @return array */ function t5_sort_editable_roles( $roles ) { uasort( $roles, ‘t5_uasort_editable_roles’ ); return $roles; } /** … Read more

Displaying a custom post type alphabetically

try this: <?php $args = array( ‘post_type’ => ‘tenant’, ‘posts_per_page’=>5, ‘orderby’=>’title’,’order’=>’ASC’); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); ?> You will find more info o custom queries here: http://codex.wordpress.org/Class_Reference/WP_Query

WP_Query order by multiple meta keys & fields

You are using meta query without setting a value. The way you are doing it is using to query posts, not to order them. Using Named Meta Queries To order your posts by different meta datas, you can give your meta queries a name and then use that to set the ordering. Here is a … Read more

Order by DESC, ASC in custom WP_Query

Try this: $args = array( ‘post_type’ => ‘post’, ‘meta_key’ => ‘pb_issue_featured’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘DESC’, ‘posts_per_page’ => $posts, ‘paged’ => $paged, ‘paged’ => 1, ‘meta_query’ => array( array( ‘key’ => ‘headline’, ‘value’ => 1, ‘compare’ => ‘!=’ ) ) ); add_filter( ‘posts_orderby’, ‘filter_query’ ); $q = new WP_Query($args); remove_filter( ‘posts_orderby’, ‘filter_query’ ); function … Read more

Sorting: custom query with orderby meta_value_num THEN by title

This is very crude but should sort your posts by year (meta_value) and then by title. It does depend on how the query is setup so it will only work with the query below or with similar ones. function alter_order_wpse_103181($order,$qry) { remove_filter(‘posts_orderby’,’alter_order’,1,2); $order = explode(‘,’,$order); $order = implode( ‘ ASC,’,$order); return $order; } add_filter(‘posts_orderby’,’alter_order_wpse_103181′,1,2); $q … Read more

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