As I created custom post type with taxonomy, when I add a new custom field, it is saving in the database but not showing in custom fields. I don't understand how to show the custom field in admin panel.
0
votes
2 Answers
0
votes
There is a very good plugin called Advanced Custom Fields for Wordpress. It's very easy to use and features conditional logic for page layouts, post type and much more.
0
votes
We can easily create a meta box without using any plugin and customize it as per our needs:
here is the Wordpress documentation to create a meta box and here is the example to easily implement it with custom post type. Here is the example:
<?php
add_action('add_meta_boxes', 'meta_box_add_function');;
function meta_box_add_function()
{
add_meta_box(
'wporg_box_id', // Unique ID
'Custom Meta Box Title', // Box title
'wporg_custom_box_html', // Content callback, must be of type callable
'post' // Post type ['post', 'custom_post_type']
);
// You can add multiple boxes like above
}
function wporg_custom_box_html($post){
echo 'What you put here, show\'s up in the meta box';
}
?>
And here you can save the post data using below hook:
<?php add_action( 'save_post', 'meta_box_save_function' ); ?>
add_action( 'load-post.php', 'post_meta_boxes_setup' );in functions.php file. Now I am using this hookadd_action( 'add_meta_boxes', 'post_meta_boxes_setup' );and now I can see the newly added custom fields in admin panel. - Pankaj Bhandarkar