Question

I've added a few different custom_post_types to my Wordpress 3 installation. They are all a bit different from eachother, and should store unique information in custom_fields. But while one may store a product_id, another will not. One will have a source_url and another will not. Rather than having to instruct my editors on which custom fields should be used with which custom posts, how can I make each custom post include its custom fields as part of the UI itself?

If you visit "daily_cartoon" you would have a screen that asks only for a title, caption, and media.
If you visit "daily_product" you would have a screen that asks only for a title, price, summary, etc.

Was it helpful?

Solution

Hi @Jonathan Sampson:

There are several plugins to make Custom Post Types easier and some allow you to define Custom Fields too, in no particular order:

As I mentioned above I've been working on one that does not provide a User Interface like these to instead an extensible API for complex field types (and simple ones too.) But after spending an hour trying to package it I realized it's not ready for distribution yet. Maybe in a few weeks.

These plugins listed above should meet your basic needs for now and I will try to make mine compatible with the data stored by all of these in the future in case you do decided to use mine in the future.

You also might find this post a bit of help too:

OTHER TIPS

you can add meta_boxes in order to have the custom fields data stored in them. since add_meta_box can be set according to post_type this will enable you to add different meta_box to different post types.

look at this post for a full example of altering the custom post type new/edit scree.

I have recently needed to address a very similar problem while working within a theme. The basis of the code was from this post and I had modified some of the code

The following is the first portion of the code I had modified.

    add_action('init', 'limited_post_type');
function my_custom_limited_post_type() 
{
  $labels = array(
    'name' => _x('Limited Post Type', 'post type general name'),
    'singular_name' => _x('Film - DVD', 'post type singular name')
  );
  $args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true, 
    'query_var' => true,
    'rewrite' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => null,
    'supports' => array('title','editor','author','thumbnail','excerpt', 'page-attributes','custom-fields' ),
    'show_in_nav_menus' => true
  ); 
  register_post_type('limited_post_type', $args);
}

The following is the second portion of the code I had modified.

foreach ( $scope as $scopeItem ) {
       switch ( $scopeItem ) {
           case "post": {
             // Output on any post screen
             if ( basename( $_SERVER['SCRIPT_FILENAME'] )=="post-new.php" || $post->post_type=="post" )
             $output = true;
             break;}              
            case "page": {
                  // Output on any page screen
                  if ( basename( $_SERVER['SCRIPT_FILENAME'] )=="page-new.php" || $post->post_type=="page" )
            $output = true;
            break;}
             case "limited_post_type": {
                                // Output on limited post_type onlye
            if ((basename( $_SERVER['SCRIPT_FILENAME'] )=="post-new.php" && $post->post_type=="limited_post_type" ) || (basename( $_SERVER['SCRIPT_FILENAME'] )=="post.php" && $post->post_type=="film_dvd" ))
                   $output = true;
                   break;
                  }

If you like please send me a message and I will gladly send you my functions.php file for your reference. This is definitely the way to make it happen though as I went through many nights of hair pulling as yourself.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top