WordPress.org

Ready to get started?Download WordPress

Forums

add post meta for custom post type (3 posts)

  1. Marc P Gangmei
    Member
    Posted 3 years ago #

    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

  2. Marc P Gangmei
    Member
    Posted 3 years ago #

    Some kindly help

  3. krauter
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic