3

I have a WordPress project that I'm using as a CMS. I also have a database with some products in it that I'd like to display on the site (gallery or portfolio maybe?) I have a custom post type for Products that I want to be editable in the wordpress admin (along with the rest of the content).

I know I have to do a custom post type (which I'm reading up on, probably will use Simple Fields plugin) but I'm not seeing a way to pull these values from a database. Products will have ProductName, URL, Category, and Type. I would want to list and add/edit/delete these in the word press admin side of course.

Any advice will be greatly appreciated. Thank you all!

EDIT: I've created the Custom Post Type for Products. Now each Product can have a Category, Subcategory, and Type, which I'm assuming will also need their own Custom Post Type if they are to be manageable right?

The layout for the products will be roughly: ProductName, Type, Category, SubCategory, Document Name, Document URL. Remember the Category, SubCategory, Type will need to be manageable and editable so I guess they will need to be custom post types as well.

Thinking about this some more, could I use the built-in categories for MY custom post type categories and have the subcategories as children of the main categories? That might be the easier way out on that end. But how would I map a custom post type of ProductType to my custom post type of Product?

Here is my product custom post type:

    /*  CUSTOM POST TYPE AREA FOR PRODUCTS   */
add_action( 'init', 'create_product_post_type' );

function create_product_post_type() 
{
    $labels = array(
        'name' => _x('Products', 'post type general name'),
        'singular_name' => _x('Product', 'post type singular name'),
        'add_new' => _x('Add New', 'products'),
        'add_new_item' => __('Add New Product'),
        'edit_item' => __('Edit Product'),
        'new_item' => __('New Product'),
        'view_item' => __('View Product'),
        'search_item' => __('Search Products'),
        'not_found' => __('No products found'),
        'not_found_in_trash' => __('No products found in Trash'),
        'parent_item_colon' => '',
        'menu_name' => 'Products'           
        );

    $args = array(
        'label' => __('Products'),
        'labels' => $labels,
        'public' => true,
        'can_export' => true,
        'show_ui' => true,
        '_builtin' => false,
        'capability_type' => 'post',
        'menu_icon' => get_bloginfo('template_url').'/functions/images/product.png',
        'hierarchial' => false,
            //'rewrite' => array( "slug" => "events" ),
        'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
        'show_in_nav_menus' => true

        );

        register_post_type( 'tf_events', $args);    
}
11
  • @drpcken - It would help if you can give a few examples of your data as well as the schema of your existing database (is it in MySQL?) Commented Apr 27, 2011 at 5:52
  • Yes Mike it will be in MySQL. The exact fields are Category, SubCategory, Type (these will all be taxonomies right?), Product, PDF Name, and a URL. Commented Apr 27, 2011 at 13:51
  • 1
    If you already have a table in your database containing your products, you can't just have wordpress magically manage this data. a custom post type stores data in wordpress' tables, using its own structure. you can manage external data with wordpress, but you need to write all of the logic yourself- create, save, update, delete, etc.. Now perhaps I misunderstand what you've got here...
    – Milo
    Commented Apr 27, 2011 at 17:09
  • 1
    To remove the main content field and show custom fields, change the 'supports' argument in your create_product_post_type function to remove 'editor' and add 'custom-fields': 'supports' => array('title', 'author', 'thumbnail', 'excerpt', 'comments', 'custom-fields' ),
    – Milo
    Commented Apr 27, 2011 at 21:11
  • 1
    yes, with the add meta box function.
    – Milo
    Commented Apr 28, 2011 at 15:51

2 Answers 2

2

What you really need to do is create Custom Taxonomies for your products instead of second custom post type. You can create taxonomies that are hierarchical like categories, or non-hierachical like tags. Give them names, slugs, etc.

This way you won't interfere with the blog categories and tags, and get a more customized result.

2

It sounds like you need to have a relationship between two different post types. In that case something like Posts 2 Posts will be required to "link up" the different post types.

Once you have the ability to perform these links, simply create custom entry boxes for your Product and ProductType post types.

As Milo mentioned above, you can remove 'editor' from the custom post types.

1
  • Thanks for the advice but I think I'm going to use ProductType as a taxonomy instead of having to create a new post type (makes sense right?). I will take your advice though when I need to relate Posts. Thanks!! Commented Apr 28, 2011 at 3:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.