Custom Post order for homepage

From a naming standpoint it seems that the term “filter” would be more appropriate since you are filtering by criteria first and then a sort (directional) is applied when you order. But that’s more a naming convention standpoint… From a code structure if you are using the check_for_popular() method in several places then it makes … Read more

Custom Post Type order by modified date and custom meta field issue

If I understand you, I believe that the following will do what you need: function orderby_mod_wpse_140999($orderby) { remove_action(‘posts_orderby’,’orderby_mod_wpse_140999′); global $wpdb; return $orderby.”, {$wpdb->posts}.post_modified DESC”; } add_filter(‘posts_orderby’,’orderby_mod_wpse_140999′); $args = array( ‘meta_key’ => ‘premium’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’ ); $q = new WP_Query($args); var_dump($q->request); The key names may be wrong and it may be (probably … Read more

Display custom post types with custom date field value (before today) & order by custom date field

I prefer to use WP_Query (for more info read “When should you use WP_Query vs query_posts() vs get_posts()?“), try this way: $args = array( ‘post_type’ => ‘soiree’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘orderby’ => ‘date_de_concert’, // you don’t need ‘meta_key’ => ‘date_de_concert’ when using meta_query //’meta_key’ => ‘date_de_concert’, ‘order’ => ‘DESC’, ‘meta_query’ => array( … Read more

WP_Query orderby breaks when using AJAX?

I believe Milo is right, it’s probably a filter affecting this. Ajax requests look like admin requests (that is, is_admin() returns true), so it’s possible that something is checking if is_admin() and adding the filter in those cases. You can set ‘suppress_filters’ => true in your args array and it will probably work. Note that … Read more

Ordering by meta_value AND date NOT WORKING with wp_query

You have to use the posts_orderby filter to do this at the mo, eg function wpse159469_posts_orderby( $orderby, $query ) { return implode( ‘ DESC,’, explode( ‘,’, str_replace( array(‘ ASC’, ‘ DESC’ ), ”, $orderby ) ) ) . ‘ DESC’; } then around your query: add_filter( ‘posts_orderby’, ‘wpse159469_posts_orderby’, 10, 2 ); $query = new WP_Query( … Read more

How to use order RAND() on WordPress?

You are right that you can’t have WordPress order the retrieved posts randomly. So you’ll have to do that yourself after you have retrieved the array of post objects. Let’s call that $my_posts. Because you don’t know how many of the posts in that array are featured, you will have to loop through them to … Read more

Arrange and separate posts

You can do some tricky thing with PHP. Here is the algorithm you could use. Query posts to get posts as alphabetical order. for/while loop starts. $t = Get first character of the title string. $temp = ” empty string. if $t != $temp echo $t. set $t = $temp. endfor/endwhile. Hope it make sense. … Read more

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