custom post and custom fields (1 post)

  1. iperez_genius
    Posted 3 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic