Advanced Custom Fields and date picker, show posts only if the day is today no matter the year

It’s a little complicated, but we can do this by directly modifying the query with a filter on posts_where. We’ll start with a query for posts with a meta value of today’s date, this is assuming a date format of yyyy-mm-dd: $date_today = date(‘Y-m-d’); $args = array( ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘key’ … Read more

Time sort with meta_key using UNIX timestamp failing due to date differences

I will caveat this by saying that I am still not 100% sure I know what you are doing, but I believe the following will sort your results by time only assuming that your meta values are proper Unix timestamps. function orderby_time_only($orderby) { remove_action(‘posts_orderby’,’orderby_time_only’); return preg_replace(‘|(.*)\s(.*)|’,’DATE_FORMAT(FROM_UNIXTIME($1),”%k%i”) $2′,$orderby); } add_filter(‘posts_orderby’,’orderby_time_only’); $args = array( ‘post_type’ => ‘event’, … Read more

How to second orderby in “pre_get_posts” by meta value or combine single date and time to timestamp

I’m outlining a solution for what you asked in your last comment, because this wouldn’t been fitting for the comment format. Code: function date_time_to_timestamp_meta( $post_id ) { // meta fields are saved in DATETIME, e.g. »2013-12-09 22:32:12« // here is only the date part relevant $datetime_date = get_post_meta( $post_id, ‘_start_date’, true ); // here is … Read more

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

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