Replicate the_date function when using a custom field

You can use date_query with is very usefull. In this snipet we get a week most viewed posts. <?php $args = array( ‘date_query’ => array( array( ‘year’ => date(‘Y’), ‘week’ => date(‘W’), ), ), ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘meta_key’ => ‘post_views_count’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘DESC’, ‘showposts’ => ‘5’ ); $my_query = … Read more

Change the date and time in wordpress

Maybe you’ld like to go to settings > general and then add a custom date format. Like d.m.1985 instead of d.m.Y Or you write a function that subtracts the time you want from the current date. Or you set the server time back to 1985. But that’s no good idea since it will affect other … Read more

Block post updates and deletion after a set period

From the PHP manual acceptable units for strtotime() are: unit ((‘sec’ | ‘second’ | ‘min’ | ‘minute’ | ‘hour’ | ‘day’ | ‘fortnight’ | ‘forthnight’ | ‘month’ | ‘year’) ‘s’?) | ‘weeks’ | daytext Try using -300 second (not seconds).

automatic send email at custom time

Creating a Scheduled Event First we’ll create a function that will schedule our event. Mine is called “mycronjob” and it will run once every day. All this code can go into your plugin’s main file, outside the main function: // create a scheduled event (if it does not exist already) function cronstarter_activation() { if( !wp_next_scheduled( … Read more

Using WP_Query to re-query and sort results using a date?

thanks for responses, Allowed me to find correct answer which I’ve posted below – $tickets_for_user = get_posts(array( ‘post_type’ => ‘ticket’, ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘event_date’, ‘order’ => ‘ASC’, ‘posts_per_page’ => 1, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘event_date’, ‘value’ => array($today,’20991231′), ‘compare’ => ‘BETWEEN’, ‘type’ => ‘DATE’, ), array( ‘key’ => … Read more

Test date object against previous date in loop

You need something like this: $args = array( ‘post_type’ => ‘post’ ); $q = new WP_Query($args); if ($q->have_posts()) { $date=””; while ($q->have_posts()) { $q->the_post(); $m = get_post_meta($post->ID,’field_id’,true); // var_dump($m); if ($date != $m) { // if $m is a strtotime compatible string echo date(‘l’,strtotime($m)); $date = $m; } echo ‘<br>’; the_title(); echo ‘<br>’; echo str_repeat(‘-‘,200); … Read more