WP_Query meta_query results date by date

My idea is following. 1. Get the array of all meta dates your events have. DISTINCT in the MySQL query means do not include duplicates. <?php /* * From https://wordpress.stackexchange.com/a/9451/11761 */ function get_all_possible_meta_dates( $key = ‘event_dates_wp’, $type=”page”, $status=”publish” ) { global $wpdb; $result = $wpdb->get_col( $wpdb->prepare( ” SELECT DISTINCT pm.meta_value FROM {$wpdb->postmeta} pm LEFT JOIN … 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

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(); }; ?>

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