Support » How-To and Troubleshooting » custom post and custom fields

custom post and custom fields

  • iperez_genius


    I have been trying to run a function from the functions.php file whenever a post is created of my custom post type.

    This is the code that i am adding to my function.php file but it doesn’t seem to create the two custom fields s and l when a post is published.

    function add_meta_values(){
    global $wpdb;
    $args = array(  'post_type' => 'sol');
    $postslist = get_posts( $args );
    foreach ($postslist as $post) :
    add_post_meta(get_the_ID(), 's', 0, true);
    add_post_meta(get_the_ID(), 'l', 0, true);
    add_action('publish_post', 'add_meta_values');

    can someone advise what i am doing wrong here.

    thanks in advance

  • The topic ‘custom post and custom fields’ is closed to new replies.