Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    Custom post types can be edited and published in the admin area like any other post would be. No need to develop a special form. You can register a post type with custom capabilities so only a user with appropriate capabilities can create such a post. Since the capabilities would be independent of other post capabilities, users needn’t be able to do other admin area tasks. For example, giving the subscriber role custom post type capabilities means they only see the custom post type and their own profile in their admin area. No posts, pages, plugins, etc.

    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @bcworkz . I would like to Insert Custom Post Types using a Form like below screenshot.

    How can I do that ?

    View post on imgur.com

    Moderator bcworkz

    (@bcworkz)

    From a plugin settings page? You can collect form data from the page and consolidate into an appropriate data array, which is then passed to wp_insert_post(). The page’s code could discern whether it’s getting a POST or GET request. If GET, just display the form with any current post data. If POST, collect submitted data and pass to the function.

    Your page can put up a tinyMCE editor by calling wp_editor(). Not sure how you’d accomplish the block editor on a plugin page.

    It could be tricky getting users who want to add such posts to your form instead of the usual edit-form-advanced.php page. The list table action links and admin menu links can be modified. Last I checked, the Add New button at the top of the list table isn’t easily altered in PHP. It may require JavaScript to change its link.

    IMO you’re better off modifying the edit-from-advanced.php page for your post type. It’s where users would naturally go to create posts of any type. It’s all meta box based, so you can add or remove boxes as desired. For examples on what’s possible, check out the Advanced Custom Fields plugin. The default editor can be suppressed and various custom fields can be added. Its source code could serve as guidance towards your own efforts you should choose to modify the default post edit page instead of making a custom plugin page.

    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @bcworkz . I am learning WordPress plugin development. I need to insert Custom Post Type. I registered custom post type using register_post_type(). I am getting below Form when I am trying to insert a New Csutom Post Types (News).

    https://i.stack.imgur.com/ICDzD.png

    **How can I customize this Form ?**

    I would like to add some radio buttons and text fields here.

    • This reply was modified 2 years, 6 months ago by mabufoysal.
    Moderator bcworkz

    (@bcworkz)

    You customize the form with meta boxes.
    https://developer.www.ads-software.com/plugins/metadata/custom-meta-boxes/

    You’ll see you can both add and remove boxes. The entire form is composed of meta boxes. It’ll take some doing to wrap your head around manipulating edit forms this way, but it’ll be much better than attempting to build your own separate form for the purpose. If nothing else, the default edit forms are what users are already familiar with.

    If you’ve not seen it yet, you’ll find the rest of the above linked document will be a very useful resource to a new plugin developer. I recommend skimming over the entire handbook to become familiar with what plugin aspects it covers. You can return later to learn portions in greater detail as the need arises. Happy coding!

    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @bcworkz .

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