Arrange Posts By Date In Order Of Closest To The Current Date
This is just a shot in the dark but I would try ordering the events in descending order instead of ascending. ‘order’ => ‘DESC’
This is just a shot in the dark but I would try ordering the events in descending order instead of ascending. ‘order’ => ‘DESC’
I tried everything I could to try sorting within the WordPress functions, but was unable to get what I wanted. I ended up following PieterGoosen’s advice and do a usort(). Here is what I have now: WP_Query $args $args = array ( ‘post_type’ => array( ‘member’ ), ‘tax_query’ => array( array( ‘taxonomy’ => ‘group’, ‘field’ … Read more
$qry_args = array( ‘post_status’ => ‘publish’, ‘post_type’ => ‘event’, // Post type ‘posts_per_page’ => -1, // ALL posts ‘orderby’ => ‘meta_value’, ‘meta_key’ => ‘year’, ‘order’ => ‘DESC’ ); add_filter( ‘posts_orderby’, ‘filter_query’ ); $all_posts = new WP_Query( $qry_args ); remove_filter( ‘posts_orderby’, ‘filter_query’ ); function filter_query( $query ) { $query .= ‘, post_modified DESC’; return $query; } … Read more
(Note to other readers: The question author and I have already discussed via chat, so I’m going straight to the code.) I think for performance reason, you should do it this way: // FIRST PART: Get the variations which are in stock. $paged = max( 1, get_query_var( ‘paged’ ) ); $wccaf_depth = array( ’19’, ‘1’ … Read more
The issue is that the default comparison for meta_query is a CHAR comparison, so the order that the numbers would be in by default would be 1, 10, 2, 3, 4, 5, 6, 7, 8, 9, a, etc. To resolve this you need to modify your meta_query as follows: ‘meta_query’ => array( array( ‘key’ => … Read more
As of writing, there is no meta query compare value that can do what you’re trying to do, which is basically “where <updated_at meta> > <build_ran_at meta>“. But there are two options that you can choose from as an alternative to using the meta_query arg: Use a raw SQL to retrieve just the IDs of … Read more
You are abusing pre_get_posts badly with that code. With pre_get_posts the point is to alter the main query. By doing that you reduce the number of necessary queries and save some processing time, plus keep the WordPress globals— $wp_query, for example– neat for any other code that might need them. What you are doing is … Read more
You can pass a space-delimited set of columns to orderby argument of WP Query: $args = array( ‘meta_key’ => ‘wp_ratings’, ‘orderby’ => ‘meta_value_num date’ ); $query = new WP_Query( $args ); You can also pass an array of key => sort_order for more granular control, for example: $args = array( ‘meta_key’ => ‘wp_ratings’, ‘orderby’ => … Read more
You can try using $wpdb, like this: // Use the global variable $wpdb; global $wpdb; // :: Define SQL command :: // You can request for the IDs only, // and then get the properties later on via get_post_meta or WC_Product() $q = ‘SELECT wp_posts.ID ‘; $q .= ‘FROM wp_posts ‘; // Attach wp_postmeta table … Read more
Solved! I was using the wrong technique to create a custom query to my taxonomy instead of using the function above I create new function that use query_vars. Here is the code function taxonomy_posts_order($query) { global $browsetype; $term = get_term_by( ‘slug’, get_query_var( ‘term’ ), get_query_var( ‘taxonomy’ ) ); if ( $query->query_vars[‘taxonomy’] == $term->slug ) { … Read more