Wordpress publish post with future date — October 17, 2018

Wordpress publish post with future date

WordPress does not provide this functionality by default. There is an option for scheduled posts but you can not publish a post with future date immediately. Tested this code with wordpress 4.9.5.

function tcm_prevent_future_type( $post_data ) {
	if ( $post_data['post_status'] == 'future' && $post_data['post_type'] == 'post' ) {
		$post_data['post_status'] = 'publish';
		remove_action('future_post', '_future_post_hook');
	}
	return $post_data;
}
add_filter('wp_insert_post_data', 'tcm_prevent_future_type');

You can change {$post_data[‘post_type’] == ‘your_post_type’} post_type to apply this filter to particular post type.

Advertisements
ACF get field default value — October 15, 2018
Jquery find difference between two arrays — September 27, 2018
jquery form validation checkbox error placement — August 9, 2018
PHP treats zero (0) as empty . How we can differentiate between zero and empty variable ? — August 8, 2018
ES6 promise chaining example — July 15, 2018

ES6 promise chaining example

var asyncAdd = (a, b) => {
    return new Promise((resolve, reject) => {
       setTimeout(()=>{
	   if( typeof a === 'number' && typeof b === 'number' ) {
		resolve(a+b);
           } else {
		reject('Arguments must be numbers only');
	   }
       },1500);
    });
};


var result = asyncAdd(5,7);

result.then((result)=>{
	console.log(`Success:-${result}`);
        //this is how we can chain promise. return a new promise again in result.
	return asyncAdd(result, 33);
}).then((result)=>{
	console.log(`Success Chained:-${result}`);
}).catch((errorMessage)=>{
    console.log(`Error :-${errorMessage}`);
});
CSS indent text — July 13, 2018