After wp_insert_post(), date_i18n() and date() outputs are adjusted to GMT

If you do not pass a date to wp_insert_post(), get_gmt_from_date() is called. And look at that function’s content: function get_gmt_from_date($string, $format=”Y-m-d H:i:s”) { preg_match(‘#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#’, $string, $matches); if ( ! $matches ) return date( $format, 0 ); $tz = get_option(‘timezone_string’); if ( $tz ) { date_default_timezone_set( $tz ); $datetime = date_create( $string ); if ( … Read more

WP_Query most viewed posts, in multiple Post Types, last 30 days, excluding a specific taxonomy term

You can try: $the_query = new WP_Query( array( ‘posts_per_page’ => ‘5’, ‘v_sortby’ => ‘views’, ‘post_type’ => array( ‘post’, ‘music’, ‘videos’, ‘albums’ ), ‘tax_query’ => array( array( ‘taxonomy’ => ‘content’, ‘field’ => ‘slug’, ‘terms’ => array( ‘indy’ ), ‘operator’ => ‘NOT IN’ ) ) )); to exclude the indy term in the content taxonomy.

Changing the post date without causing 404 error

You’ll need to add 301 redirects for the old URL to the new one. Your best bet is to do this via .htaccess, in your theme, or using a plugin like one of these: http://wordpress.org/plugins/simple-301-redirects/ http://wordpress.org/plugins/safe-redirect-manager/ Edit: Another option OPtion 2 would be to disregard the date in the URI altogether. You could unset them … Read more

If modified on same day, show only time

Give this a try: if(get_the_modified_date(‘zY’)==date(‘zY’)) { the_modified_date(‘g:i a’); } else { the_modified_date(‘F j, Y’); echo ‘ at ‘; the_modified_date(‘g:i a’); } It checks that the modified date is the current day. If it is, it only displays the modified time. Otherwise it displays both the date and time.

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