1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[HELP] WP Custom Fields: add_post_meta ?

Discussion in 'Blogging' started by dheaven, Jul 13, 2009.

  1. dheaven

    dheaven Junior Member

    Joined:
    Jan 17, 2009
    Messages:
    110
    Likes Received:
    33
    Occupation:
    webdesigner
    Location:
    GMT +2
    I would like to add a custom field to the WP Post
    name: icon
    value: $my_value

    so i tried something like this


    $favicon = get_option('aa_favicon');
    $addicon = add_post_meta($post_ID, 'icon', $favicon, true);

    $post_data = compact('....,'addicon')

    not working.... :(

    Any ideas? be explicit please...i can't even call myself a noob at php.

    Thank You

    Code:
    $pd = $days;
            
            if ($pd == 'now') {
            $post_status = 'publish';
            $post_date= current_time('mysql');
            $post_date_gmt= current_time('mysql', 1);        
            } else {
            $tomorrow = mktime(0, 0, 0, date("m"), date("d")+$pd, date("y"));
            $post_date_gmt=date("Y-m-d", $tomorrow). " " . rand(10, 23). ":" . rand(10, 59). ":" . rand(10, 59); 
            $post_date = $post_date_gmt;
            $post_status = 'future';    
            }
    
            $post_author=1;
            $post_category = array($categorie);
            $post_content=$content;    
    
            $badchars = array(",", ":", "(", ")", "]", "[", "?", "!", ";", "-");
            $title2 = str_replace($badchars, "", $title);        
            
            $items = explode(' ', $title2);
            $thetag = array();        
            for($k = 0, $l = count($items); $k < $l; ++$k){        
                $long = strlen($items[$k]);
                if ($long > 3) {
                    $thetag[] = $items[$k];
                }
            }            
            $tags_input = array($thetag[0],$thetag[1],$thetag[2],$thetag[3],$thetag[4],$thetag[5],$thetag[6],$thetag[7],$thetag[8],$thetag[9]);
    
            $post_title = trim($title);
            $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category', 'post_status', 'tags_input');
            $post_data = add_magic_quotes($post_data);
            $post_ID = wp_insert_post($post_data);
            if ( is_wp_error( $post_ID ) )
            echo "\n" . $post_ID->get_error_message();
            do_action('publish_phone', $post_ID);
            
            echo "Created Post for <a href=\"$target_url\">$title</a><br/>";
    
     
  2. Jcsarokin

    Jcsarokin Power Member

    Joined:
    Mar 2, 2009
    Messages:
    718
    Likes Received:
    1,015
    Location:
    Los Angeles / Beverly Hills
    I dont think you can use php in WP unless you have the wordpress plugin called exec-php.

    Download it here:
    Code:
    http://wordpress.org/extend/plugins/exec-php/
    
    Hope this helps
     
  3. dheaven

    dheaven Junior Member

    Joined:
    Jan 17, 2009
    Messages:
    110
    Likes Received:
    33
    Occupation:
    webdesigner
    Location:
    GMT +2
    fixxed it

    ALL DONE!

    thx
    thread closed