[Plugin: Content Scheduler] How to insert multiple (diffirent) dates to each post:
-
How to insert multiple (diffirent) dates to each post:
In my case im getting dates from the content of the post (Y-m-d H:i:s) .
All my posts need to have expiring date.
All i have to do is to create automatically two custom fields :add_post_meta($post_ID, '_cs-enable-schedule', 'Enable', true); blah blah.. and <code>add_post_meta( $id, '_cs-expire-date', $date , true );</code>
blah blah..
The first is easy . Add this function to functions.php :
add_action('publish_page', 'add_custom_field_automatically'); add_action('publish_post', 'add_custom_field_automatically'); function add_custom_field_automatically($post_ID) { global $wpdb; if(!wp_is_post_revision($post_ID)) { add_post_meta($post_ID, '_cs-enable-schedule', 'Enable', true); } }
The second one.. for date needs some searching in the post content because i have more stuff in there.May be a regex for my content.So here what i ended up:
function dh_add_fields( $id, $post ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; if( ! get_post_meta( $id, '', true ) ) { if ( preg_match( '|<[h4]+>(.*)</[h4>]+>|U', $post->post_content, $matches) ) { add_post_meta( $id, '_cs-expire-date', esc_url_raw( $matches[1] ), true ); } }
The regex:|<[h4]+>(.*)</[h4>]+>|U’ finds date beetween …<h4>2012-03-18 20:50:00</h4>… and $matches[1] is actually the date.Update posts all together. Thats it!!
You wont see it in posts custom fields but you’ll see the meta box of content scheduler to be enabled and the date automatically inserted!!!! Wowww. Thank you freakingid.
- The topic ‘[Plugin: Content Scheduler] How to insert multiple (diffirent) dates to each post:’ is closed to new replies.