Order posts by more than one variable (meta_key and publish date AND time)

I found this link about “a more powerful ORDER BY in WordPress 4.0” and it led me to try this code: <?php $query = new WP_Query( array( ‘post_type’ => ‘result’, ‘posts_per_page’ => 100, //’paged’ => $paged, ‘meta_key’ => ‘event_date_results’, ‘orderby’ => array( ‘meta_value_num’ => ‘DESC’, ‘post_date’ => ‘DESC’), //’order’ => ‘DESC’, ‘meta_value’ => date(‘Ymd’), ‘meta_compare’ … Read more

Order terms by creation date

If you want to achieve that, then you need to add creation_date for each taxonomy, hooked with ‘create_category’ (or create_YOURTAXONOMYNAME) function. lets say,for example, you add a new category : add_action( “create_category”, ‘my_func123’, 10, 2 ); function my_func123( $term_id, $tt_id){ update_option(‘my_taxnm_date_’.$term_id, time()); } then later, anytime, you will be able to get the creation date … Read more

Random order of the 5 most popular posts

You’re using the order parameter incorrectly for WP_Query. order (string | array) – Designates the ascending or descending order of the ‘orderby’ parameter. Defaults to ‘DESC’. An array can be used for multiple order/orderby sets. ‘ASC’ – ascending order from lowest to highest values (1, 2, 3; a, b, c). ‘DESC’ – descending order from … Read more

Sort posts by meta value with get method

You’re not actually using the $_GET[‘orderby’]-value anywhere. What you’re doing in your code is ordering by the text_date-meta value, always. If you want to order by date by default, and when $_GET[‘orderby’] is set to default orderby-values or if $_GET[‘orderby_meta’] is set, order by those instead you need to do something like this: if (isset($_GET[‘orderby’]){ … Read more

query_posts based on a meta_key

This answer is pretty covering for this I think: $args = array( ‘post_type’ => ‘brand’, ‘posts_per_page’ => 999, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘wpcf-sorter’, ‘compare’ => ‘NOT EXISTS’, ), array( ‘key’ => ‘wpcf-sorter’, ‘compare’ => ‘EXISTS’, ), ), ‘orderby’ => array( ‘meta_value’ => ‘DESC’, ‘date’ => ‘DESC’ ), ); That should … Read more

Pin to Top Functionality using orderby custom field then event date

I had a similar aproach some days ago //….. ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘pin_clause’ = array( ‘meta_key’ => ‘pin_to_top’, ‘meta_type’ => ‘NUMERIC’, ‘meta_value_num’ => ‘1’, ‘compare’ => ‘=’ ) ), array( ‘date_clause’ => array( ‘meta_key’ => ‘_EventStartDate’, ‘meta_type’ => ‘DATETIME’, ‘meta_value’ => ‘$today’, ‘compare’ => ‘>=’ ) ) ), ‘orderby’ => array( … Read more

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