Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('publish_post', 'add_custom_field_automatically');
- function add_custom_field_automatically($post_ID) {
- global $wpdb;
- if(!wp_is_post_revision($post_ID)) {
- update_post_meta($post_ID, 'votes_count', '0');
- }
- }
- add_action( 'transition_post_status', 'wpse120996_post_status_publish', 10, 3 );
- function wpse120996_post_status_publish( $new_status, $old_status, $post_ID ) {
- if ( $new_status == 'publish' && $old_status == 'pending' ) {
- global $wpdb;
- if(!wp_is_post_revision($post_ID)) {
- update_post_meta($post_ID, 'votes_count', '0');
- }
- }}
- add_action('publish_post', 'wpse120996_add_custom_field_automatically');
- function wpse120996_add_custom_field_automatically($post_id) {
- global $wpdb;
- $votes_count = get_post_meta($post_id, 'votes_count', true);
- if( empty( $votes_count ) && ! wp_is_post_revision( $post_id ) ) {
- update_post_meta($post_id, 'votes_count', '0');
- }
- }
- //it's specific because you specify the hook like this {$old_status}_to_{$new_status}
- add_action( 'auto-draft_to_publish', 'wpse120996_specific_post_status_transition' );
- function wpse120996_specific_post_status_transition() {
- //your code
- }
- //it's generic because you specify post statuses inside the function not via the hook
- add_action( 'transition_post_status', 'wpse120996_generic_post_status_transition', 10, 3 );
- function wpse120996_generic_post_status_transition( $new_status, $old_status, $post ) {
- if ( $new_status == 'publish' && $old_status == 'auto-draft' ) {
- //your code
- }
- }
- add_action('save_post', 'wpse120996_on_creation_not_update');
- function wpse120996_on_creation_not_update($post_id) {
- //get_post( $post_id ) == null checks if the post is not yet in the database
- if( get_post( $post_id ) == null ) {
- //your code
- }
- }
- add_action('publish_post', 'add_custom_field_automatically');
- function add_custom_field_automatically($post_ID) {
- global $wpdb;
- $meta_count = get_post_meta($post_ID, "votes_count", true);
- if($meta_count == '') {
- if(!wp_is_post_revision($post_ID)) {
- update_post_meta($post_ID, 'votes_count', '0');
- }
- }
- }
- add_action( 'publish_post' , 'my_func' , 10 , 2 );
- function my_func( $ID , $post )
- {
- if ( $post->post_date != $post->post_modified )
- {
- //THIS IS AN UPDATE
- }
- else
- {
- //POST JUST GOT PUBLISHED
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement