Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. // Create custom field on post publish
  2. function wpse_custom_field_on_publish( $new, $old, $post ) {
  3.  
  4. if ( $new == 'publish' && $old != 'publish' && !get_post_meta( $post->ID, 'post_views_count', true ) ) {
  5. add_post_meta( $post->ID, 'post_views', rand(829, 1013), true );
  6. }
  7.  
  8. }
  9. add_action( 'transition_post_status', 'wpse_custom_field_on_publish', 10, 3 );
  10.  
  11. // Create custom field on post publish
  12. function wpse_custom_field_on_publish( $new, $old, $post ) {
  13.  
  14. if ( $new == 'publish' && $old != 'publish' ) {
  15.  
  16. if ( !get_post_meta( $post->ID, 'post_views_count', true ) ) {
  17. add_post_meta( $post->ID, 'post_views_count', rand(829, 1013), true );
  18. } else {
  19. update_post_meta( $post->ID, 'post_views_count', rand(829, 1013) );
  20. }
  21.  
  22. }
  23.  
  24. }
  25. add_action( 'transition_post_status', 'wpse_custom_field_on_publish', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement