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

Fetch posts from current week (Sunday to Saturday)

You can try: ‘date_query’ => array( array( ‘year’ => date( ‘Y’ ), ‘week’ => strftime( ‘%U’ ), ), ), where %U is: Week number of the given year, starting with the first Sunday as the first week or ‘date_query’ => array( array( ‘after’ => strtotime( ‘last Sunday’ ), ), ),

Styling the date format with date_i18n

Just use date_i18n in multiple places with PHP date arguments just for what you need: if ( $date = get_post_meta( $thepostid, ‘_sale_price_dates_to’, true ) ) { $sale_price_dates_to = ‘<span class=”m”>’ . date_i18n( ‘M’, $date ) . ‘</span> ‘ . ‘<span class=”d”>’ . date_i18n( ‘j’, $date ) . ‘</span> ‘ . ‘<span class=”y”>’ . date_i18n( ‘Y’, … Read more

Use meta_query to display events by date in custom field

Simpler CODE: Logically, when you check >= for both _event_start_date and _event_end_date, that automatically covers the BETWEEN check. So the following CODE should work: $termName = get_queried_object()->name; $termSlug = get_queried_object()->slug; $event1 = current_time( ‘Y-m-d’ ); $args = array( ‘post_type’ => ‘event’, ‘event-categories’ => $termSlug, ‘post_status’ => ‘publish’, ‘posts_per_page’ => 10, ‘order’ => ‘ASC’, ‘meta_query’ => … Read more

WordPress post dating – pre 1901?

This is something totally new to me, so I did some research. What an exciting question! I had a look at the how WP saves the date when a post is saved. WP runs post date through wp_checkdate(), which uses PHP native function checkdate(). According to the PHP docs checkdate() considers any year between 1 … Read more

Check if date of post is yesterday

As you discovered, one possible solution is something like: <?php $w_h = $w_d = 0; ?> <?php while (have_posts()) : the_post(); ?> <?php if ( date(‘Yz’) == get_the_time(‘Yz’) ) { if (!$w_d++) echo ‘Today<br />’; } elseif ( date(‘Yz’)-1 == get_the_time(‘Yz’) ) { if (!$w_h++) echo ‘Yesterday<br />’; } else { echo the_date(); }; ?>

Query current and future events, ordered by begin date

This happens because of the OR relation on meta_query and the way WordPress generates the actual query string. You need to leave out the meta_key and orderby from the query args and hook into the posts_clauses filter to modify the where and orderby pieces of the query: function wpse_130954_orderby_fix($pieces){ global $wpdb; $pieces[‘where’] .= ” AND … Read more

Date query not inclusive despite parameter being true

If you only want to work with yyyy-mm-dd strings, for example ‘2014-10-10’, you could do something like: ‘before’ => ‘2014-10-10 + 1 day – 1 second’, ‘before’ => ‘2014-10-10 + 86399 seconds’, ‘before’ => ‘tomorrow 2014-10-10 – 1 second’, ‘before’ => ‘2014-10-10 tomorrow – 1 second’, or just append ’23:59:59′ to your yyyy-mm-dd string to … Read more