Is there any way to assign a random value to a custom field for each post ! Wp plugin are available to change the mass value of custom field but in my case i would like to assign random value to the custom field name for each post! i try the code below but for some reason i m not able to make it work ! Will be great if someone can figure this out ! 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; $rand_num = rand(144, 544); if(!wp_is_post_revision($post_ID)) { add_post_meta($post_ID, 'views', '$rand_num', true); } } PHP: here views is the custom field name and $rand_num is the random nu generated between 144 and 544 ! But this is not working!
What is happening instead of the expected behaviour? What (if anything) have you already done to debug it?