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

Adding custom meta boxes to specified custom post type

The fourth parameter is $screen, which in your case is set to post, so all you have to do is specify the website post type instead:

function website_add_meta_box() {
    add_meta_box(
        'website-website',
        __('Website', 'website'),
        'website_html',
        'website',
        'normal',
        'default'
    );
}

Documentation here: https://developer.wordpress.org/reference/functions/add_meta_box/

As an aside, your save_post hook applies to any post or custom post type being saved, but if website_website_url and website_website_source_code only apply to the website post type, you can add an additional check:

function website_save($post_id) {
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
    if (!isset($_POST['website_nonce']) || !wp_verify_nonce($_POST['website_nonce'], '_website_nonce' )) return;
    if (!current_user_can('edit_post', $post_id)) return;
    if (get_post_type($post_id) !== 'website') return;

    if (isset($_POST['website_website_url']))
        update_post_meta($post_id, 'website_website_url', esc_attr($_POST['website_website_url']));
    if (isset($_POST['website_website_source_code']))
        update_post_meta($post_id, 'website_website_source_code', esc_attr($_POST['website_website_source_code']));
}

Related Posts:

  1. Updating post meta for custom post types
  2. dynamically generating plugin syntax
  3. How to add jquery to my custom post type wp plugin
  4. Custom media upload content for inserting custom post shortcode
  5. Redesigning Custom Post Type “Add New” page
  6. How to Remove Certain Screen Options and Meta Boxes from add/edit post type?
  7. Creating a default Custom Post Template that a Theme can override
  8. Update Multiple Post Meta for the Same Post In One call?
  9. How to load a new template page according to a particular URL?
  10. How to get the custom page get_permalink?
  11. update a post meta from a single table cell TablePress
  12. update custom post type meta from a shortcode
  13. How can I add a custom meta value on file upload?
  14. remove custom taxonomy metabox form custom post type
  15. Custom Post Type Statuses
  16. How to Build a Movie Library in WordPress 3.x
  17. How to add multiple featured image in meta box in post editor?
  18. Plugin “Meta Box”: Implementing meta boxes in custom post type
  19. Get image URL from media library in input
  20. Way to hook into a sidebar call to replace it with a custom sidebar
  21. RW Meta Box ,Problem setting post title
  22. Loco Translate: Custom Post and Custom Taxonomy Labels not translated in wp-admin menu
  23. Is Wrapping intval() Around esc_attr() Redundant for Escaping Input?
  24. Correct way to make meta box with more than one meta field secure
  25. Is it possible to create Custom Post plug-in?
  26. get_post_type on post.php
  27. All of my custom posttypes are 404’ing
  28. Save / Show multi line text in metabox
  29. Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
  30. Making a Template for a CPT created by a plugin
  31. Metabox not show in categories custom post type cmb2
  32. How can I make my metabox appear?
  33. How to inform the user that the save was not successful?
  34. How can I change the meta_key for a particular piece of information?
  35. Unable to delete custom post types, confusion around capabilities
  36. Adding CSS to custom post type admin page causes error
  37. Custom fields for custom post type
  38. Redirect to another page using contact form 7? [closed]
  39. Disable Individual Plugins (specifically in Custom Post Types) on a per-post basis?
  40. Using ACF default value to autoincrement a number field
  41. Date format – Meta Box plugin
  42. How to Resize the Custom Post Images?
  43. Amazon.com intergration with WordPress?
  44. Set Multiple Meta Values as an Array Using dispatch( ‘core/editor’ ).editPost() Call in Gutenberg/JS
  45. Plugin generated unexpected output – No PHP errors
  46. Remember the Meta Value With Radio Buttons
  47. Custom Post Type template for homepage
  48. Custom Post Type, Custom Columns List
  49. Error Metabox Warning: call_user_func() expects parameter 1 to be a valid callback
  50. Custom Meta box change size
  51. Need to edit author permissions | custom taxonomy
  52. Is it possible to pin a post in second position from top
  53. How to get the custom field value using SQL query
  54. Check if theme supports sidebar
  55. Help to Create a Simple Plugin to make a post
  56. submit two file input fields in the same form
  57. How to display the category name in the tab and post inside the tab in WordPress?
  58. custom post type plugin error [closed]
  59. How to display the custom post related blog by category?
  60. Add an action based on custom post meta field
  61. Problem with checked box on wp car manager plugin
  62. how to auto random increment for post view
  63. Ultimate Members Default Post Layout problem
  64. custom post type get_posts() function not work
  65. Create multiple posts when a custom post is created
  66. How to securely controlling data without keeping it in postmeta?
  67. $wpdb->insert not working inside save_post tag
  68. Cannot view Custom Post Type no matter what I try
  69. “Enable Media Replace” plugin does not update serialized object in WPMeta
  70. Performance considerations – postmeta table versus new table for custom posts with foreign keys?
  71. How to get post that has non zero or greater than zero meta value
  72. Delete postmeta when uninstall/delete plugin
  73. Displaying image from a repeatable group
  74. Storing values in Post Meta vs new tables
  75. Synch Custom Post Types (and Custom Fields, Cats, etc.) Between WordPress Sites
  76. get_option include in my adsense
  77. How can i do custom author list?
  78. Making a Custom Post Type Publish Loop
  79. WordPress User Frontend Editing Custom Fields
  80. wordpress last all added get meta value by post id
  81. Is an Office a custom post type [closed]
  82. Meta box not displaying on the plugin page
  83. add_meta_box showing blank screen in my page
  84. Wrong block appender button showing
  85. How to access the page without registering in wordpress
  86. CPT template is not being automatically used single post pages
  87. How to make content as required in custom post type?
  88. public custom posts not showing in my wordpress plugin
  89. How to provide page_template path in custom plugin using WordPress
  90. Remove H1 title in admin post edit screen
  91. How to Display News in a Timeline with Headline, Category, and Time?
  92. Which method is best to enqueue scripts
  93. Is there a WordPress Plugin that allows voting “does this coupon work” on specific links like Retailmenot
  94. Force plugin to fail activation
  95. Building plugin with changeable custom post type values…advice needed
  96. Preset custom fields
  97. How do I add a textarea (multirow) option to my WordPress plugin?
  98. WordPress CPT Url metabox collection
  99. is there a way I can add or remove some plugin options?
  100. WordPress show different custom post type
Categories plugins Tags custom-post-types, metabox, plugin-development, plugins, post-meta
Any way to change post/page status when editing page?
Load more posts in the same category – Ajax + Timber

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