• I am using below code to create Custom Post Types.

    
    $supports = array(
                        'title', // post title
                        'editor', // post content
                        'author', // post author
                        'thumbnail', // featured images
                        'excerpt', // post excerpt
                        'custom-fields', // custom fields
                        'comments', // post comments
                        'revisions', // post revisions
                        'post-formats', // post formats
                    );
    
                    $labels = array(
                        'name' => _x('news', 'plural'),
                        'singular_name' => _x('news', 'singular'),
                        'menu_name' => _x('news', 'admin menu'),
                        'name_admin_bar' => _x('news', 'admin bar'),
                        'add_new' => _x('Add New', 'add new'),
                        'add_new_item' => __('Add New news'),
                        'new_item' => __('New news'),
                        'edit_item' => __('Edit news'),
                        'view_item' => __('View news'),
                        'all_items' => __('All news'),
                        'search_items' => __('Search news'),
                        'not_found' => __('No news found.'),
                    );
    
                    $args = array(
                        'supports' => $supports,
                        'labels' => $labels,
                        'public' => true,
                        'query_var' => true,
                        'rewrite' => array('slug' => 'news'),
                        'has_archive' => true,
                        'hierarchical' => false,
                    );
                    register_post_type('news', $args);

    I am getting below Form at time of Custom Post entry.

    View post on imgur.com

    How can I add another Text field after Title named Name ?

    • This topic was modified 2 years, 6 months ago by mabufoysal.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You can use the ‘edit_form_after_title’ action to output any HTML you desire. The current WP_Post object is passed to your callback. You can use its ID property to fetch the field’s current value, if it exists.

    You can output a form’s input element, but WP will not do anything with the added data when the post is saved. You’ll need to manage that aspect as well. There are a number of possible action hooks you could use for this, “save_post” is commonly used, but there may be better ones. For example, "save_post_{$post->post_type}" would probably be better. You can save the field value anywhere that makes sense, but the postmeta table is usually the best choice.

Viewing 1 replies (of 1 total)
  • The topic ‘Custom Post Types’ is closed to new replies.