I’ve set up 3 custom post types for the wordpress website I’m working on using the following code in functions.php:
if ( function_exists('add_action') )
{
add_action( 'init', 'create_post_types' );
function create_post_types()
{
register_post_type('dj',Array('labels' => Array('name' => "DJ’s",'singular_name' => "DJ"),'public' => true,'has_archive' => true));
register_post_type('gerecht',Array('labels' => Array('name' => "Gerechten",'singular_name' => "Gerecht"),'public' => true,'has_archive' => true));
register_post_type('agenda',Array('labels' => Array('name' => "Agenda",'singular_name' => "Evenement"),'public' => true,'has_archive' => true));
}
}
But in the wp-admin screen i can’t add any meta info to the post. How do i fix this, or is it just not possible?
Edit: I don’t want to use any plugin for this, but write the code myself.
You need to add supports field to your initialization array, like this:
By default it’s only title and editor, that’s why you probably do not get them in the backend.
Full list of supported features looks like this:
important for hierarchical post types, so you can select the parent
post.
Here is a nice writeup on the topic: Custom post types in WordPress.
Also here is the better place to ask WordPress related questions: WordPress Answers.
Personally, I would use the plugin called Advanced Custom Fields, which offers quite a nice interface to do this, as it offers a wide range of options.
You can use the above in conjunction with Custom Post Type UI, which allows you to create custom post types and taxonimies with a UI. FYI, you can ‘Get the code’ and place it into your functions.php.
An example of this:
you might want to look at the array and add your own descriptive data, i.e. where it says
Item
forsingular_name
andname
.