How to mass-change custom field value of a custom field name in wordpress

Discussion in 'WordPress' started by mike4uuu, Apr 19, 2011.

  1. #1
    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!
     
    mike4uuu, Apr 19, 2011 IP
  2. kiramanic

    kiramanic Peon

    Messages:
    205
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What is happening instead of the expected behaviour? What (if anything) have you already done to debug it?
     
    kiramanic, Apr 20, 2011 IP