• add_action('publish_post', 'add_author_fields');
    function add_author_fields($post_ID) {
    global $wpdb;
    $user_id = $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $post_ID");
    $sitelink = $wpdb->get_var("SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = 'sitename' AND user_id = $user_id");
    add_post_meta($post_ID, 'sitename', $sitelink, true);
    }

    This is a working code for the default post type ‘post’. It automatically add a custom field
    but it does not work on other custom post type

    Can anyone help me

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Archie Webmaker

    (@weblogian)

    Some kindly help

    add_post_meta () should work on any custom post type.

    You have to make sure that the $post_ID is correct, and remember that meta value names that start with ‘_’ underscore are hidden and will not show up in the post edit screen.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘add post meta for custom post type’ is closed to new replies.