Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Custom fields for custom post type

You need to add your own metabox for the custom post type created. You can use the action add_meta_boxes_{cpt_slug}

add_action( 'add_meta_boxes_' . $cpt_public_slug, 'adding_custom_meta_boxes' );
add_action( 'save_post', 'save_metabox' , 10, 2 );

function adding_custom_meta_boxes(){
    global $cpt_public_slug;
    add_meta_box(
        'plugin-site',
        __( 'Website', 'text_domain' ),
        'cpt_form_site_Render',
        $cpt_public_slug,
        'normal',
        'high'
    );
}

function cpt_form_site_Render(){
    global $post;

    $post_meta = get_post_meta($post->ID); 

    // render the input field
    ?>
     <input type="text" name="meta_key" value="<?php echo $post_meta['meta_value'][0]; ?>"/>
    <?php
    // do it for all your metas
}

function save_metabox($post_id, $post){

    foreach ($_POST as $the_posted_key=>$the_posted_value) {
        if (strpos($the_posted_key, brozzme_passport_config::$custom_fields_prefix)!==false) {
            update_post_meta($post_id, $the_posted_key, $the_posted_value);
        }
    }
}

Related Posts:

  1. How to have the right design for a custom post type without accessing themes
  2. ACF in wordpress
  3. Custom post type in Custom widget – $listItem
  4. Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
  5. Show Post columns to specific users on condition
  6. Run query on specific admin options page and send results to select field in another function
  7. Custom post type that lets users create a set of posts?
  8. what is the correct way to compare dates in a WP query_posts meta_query
  9. Advanced search form with filters for custom taxonomies and custom fields
  10. How to Add Custom Taxonomy To Woocommerce Plugin
  11. Development of a WordPress Search Plugin – Best Practices
  12. Prevent trash/delete action on specific post types
  13. Custom field values deleted when trashing custom post type
  14. How to get all custom fields of any post type
  15. How to add custom content template part for a custom post type on main query using a plugin
  16. Admin Area Custom Type Search By Meta Fields Without Title & Content
  17. How do I Paginate Search Results for Custom Post Types?
  18. echo value from ‘select’ field type into page template using cmb2?
  19. wordpress plugin error handling
  20. register_taxonomy with multiple object type and update_count_callback
  21. How often do you need to register_post_type?
  22. How Can I save multiple records in same meta key?
  23. How to use a dedicated template for the Custom Post Type from a plugin?
  24. Detect meta value changes when post is updated (post_updated)
  25. Search everything (posts, pages, tags, cpt, meta)
  26. Updating post meta for custom post types
  27. How to get source of custom meta image?
  28. WP Query group/order by category name
  29. update a post meta from a single table cell TablePress
  30. update custom post type meta from a shortcode
  31. Remove POST_TYPE from custom post type permalink
  32. Displaying Meta Box Image
  33. Using posts and postmeta table to store custom Address Book Plugin data
  34. How to register custom post types in a plugin?
  35. How to add multiple featured image in meta box in post editor?
  36. how to set default value for checkbox in wordpress
  37. How to append element after thumbnail
  38. ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
  39. Formatting custom meta box date from YYYY/MM/DD to a more readable alternative
  40. handling csv data with a custom post type
  41. Customize permalink when creating a post
  42. Custom Post Type | Fatal Error on register_post_type()
  43. Set object terms not working on plugin activation
  44. How to add the post ID (or any other post data) to a Contact Form 7 mail?
  45. need advice on how to do a lists using custom post types – taxonomy vs postmeta
  46. Create a random unique 6 digit number as custom field for custom post type
  47. Custom Post Type Navigation on Custom Field
  48. how to interconnect custom post types?
  49. Metadata for a taxonomy – is there any WordPress way of doing this?
  50. List all images from a single post meta value
  51. Populate Custom Fields in a Custom Post Type?
  52. Insert Multiple Post with Same Publish Button
  53. custom post type not showing in menu
  54. Custom posts don’t work
  55. Meta Key Value in current-user-only loop
  56. Adding a custom post type taxonomy template in plugin
  57. How to check if user meta field is empty in conditional else statement
  58. Replace text in post from cvs
  59. Custom Post Types. Are there any disadvantages/advantages in using a plugin to develop them?
  60. Give a permalink to Custom Post Types without title
  61. How to implement a Google map store locator
  62. Posting to a Custom Post Type from front end – user generated content
  63. Update Post Meta for a logged in user
  64. Getting meta in editor plugin, and event triggering issue
  65. Orderby CPT custom fields not working
  66. Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
  67. A better way to add a meta box to custom post types
  68. Two Custom Post Types Many to Many Relationship
  69. get_post_meta not working on publishing
  70. Addition of custom option panel crashes Media Library & Admin Area
  71. How do I set all of a particular post meta to a value within the custom post type I’m in?
  72. Dynamic dropdown select values depending on other custom field value
  73. Tracking changes in admin-page so user gets warning when leaving the page
  74. Metabox not show in categories custom post type cmb2
  75. Types plugin custom post add_action hooks
  76. how can i show a google map in custom post type
  77. delete duplicate meta_value with same post_id
  78. Search CPT Title AND Meta
  79. updating one custom meta field only
  80. Add a class to post_class if more than one post shares same meta_value_num
  81. Fill custom fields when saving custom post types
  82. Add a meta field to the list of results for a custom post type
  83. Empty meta-box returns publishdate if no value is set?
  84. Writing a custom Glossary plugin
  85. Filter search posts by post meta?
  86. Mandatory field in Custom post
  87. Custom fields for post or terms which don’t update on post update
  88. How to store the third party script with HTML code in the wordpress custom input field?
  89. Custom Post Type meta data getting deleted on bulk editing taxonomies
  90. Auto update publish date of CPT Post if default post custom field value match to cpt post CF Value
  91. How to upload an image to a custom post type
  92. Create multiple posts when a custom post is created
  93. How to keep custom post type related information
  94. How can I add a meta[] to my custom post type and search by term with the Rest API?
  95. Show posts from WP Custom Post Type selected from a field in a metabox
  96. Creating an archive page or simple template to list all values of a custom field of specific post type listing
  97. Where is get_post_meta value located?
  98. Custom meta fields not showing up in WP_Response Object via custom endpoint
  99. Restrict Custom Post Type to One Item
  100. Custom Post Type Front Page Gives 404
Categories custom-post-types Tags custom-field, custom-post-types, plugin-development, plugins, post-meta
Has is_archived() for sites in a multisite changed with WP 4.7?
How to put Word documents online so they can be downloaded, printed and read via a web page? [closed]

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress