Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create custom field on post publish
- function wpse_custom_field_on_publish( $new, $old, $post ) {
- if ( $new == 'publish' && $old != 'publish' && !get_post_meta( $post->ID, 'post_views_count', true ) ) {
- add_post_meta( $post->ID, 'post_views', rand(829, 1013), true );
- }
- }
- add_action( 'transition_post_status', 'wpse_custom_field_on_publish', 10, 3 );
- // Create custom field on post publish
- function wpse_custom_field_on_publish( $new, $old, $post ) {
- if ( $new == 'publish' && $old != 'publish' ) {
- if ( !get_post_meta( $post->ID, 'post_views_count', true ) ) {
- add_post_meta( $post->ID, 'post_views_count', rand(829, 1013), true );
- } else {
- update_post_meta( $post->ID, 'post_views_count', rand(829, 1013) );
- }
- }
- }
- add_action( 'transition_post_status', 'wpse_custom_field_on_publish', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement