Default sort on admin columns with meta date hides draft posts with empty date value

I too was struggling with this (only I was sorting by a text-based meta value). Here’s what seems to have fixed the problem: $meta_query = array( ‘relation’ => ‘OR’, array( ‘key’ => ‘property_reference’, ‘value’ => false, ‘type’ => ‘BOOLEAN’, ), array( ‘key’ => ‘property_reference’, ‘compare’ => ‘NOT EXISTS’, ‘value’ => ”, //have to set value … Read more

Query posts with numeric meta values within a given range

I ended up finding two solutions within WordPress’ capabilities. Storing available rather than unavailable dates The first solution would be to have the agency select all available dates rather than selecting unavailable dates. Our example listing would then have a custom field listing_available: update_post_meta($post_id, “listing_available”, “/20140101/20140102/20140103/20140104/”); I would then be able to run the following … Read more

About Time conditionals

Here is how it works for me with minor changes: global $post; $post_created = strtotime($post->post_date); $sixMonthsAgo = strtotime(‘-6 months’); $human_time=”hace “. human_time_diff( get_the_time(‘U’), current_time(‘timestamp’) ); $mobile = wp_is_mobile(); if ($post_created > $sixMonthsAgo && $mobile) { the_time(‘j. M .Y’); } elseif( $post_created > $sixMonthsAgo && !$mobile) { the_time(‘j. F .Y’); } else { echo $human_time; } … Read more

Add a link to display posts with a specific tag within a date range

Check out wp_get_archives(). As described by the Function Reference linked to above, “This function displays a date-based archives list. This tag can be used anywhere within a template.” It gives several examples of how you can use the function, including if you wish to use a dropdown rather than listing every archive. By default this … Read more

Get last revision author, author-link and date

To get the_modified_author() we have to look in the folder wp-includes and search for the author-template.php. Line 101 shows: /** * Display the name of the author who last edited the current post, * if the author’s ID is available. * * @since 2.8.0 * * @see get_the_author() */ function the_modified_author() { echo get_the_modified_author(); } … Read more

pre_get_posts query between 2 dates (date stored in custom post meta)

You can always use a BETWEEN comparison in your query, I have used this, maybe you can adapt it to work in your situation. It avoids doing multiple checks for no reason 🙂 $first_date = 110501; $second_date = 170514; $meta_query = array( ‘key’ => ‘_exm_date’, ‘value’ => array($first_date, $second_date ), ‘type’ => ‘DATE’, ‘compare’ => … Read more