0

I want to view the details of a product in single.php. The product is inserted in a newly added table "products" in the wordpress database and it has no post_type or post_id.

2
Contributors
3
Replies
23
Views
2 Years
Discussion Span
Last Post by lps
1

For a wordpress site, please do not add the table manually, normally what we done is use a custom post type by nested the code into functions.php

//add "product" custom post
    add_action( 'init', 'create_product_post_types' );
    function create_product_post_types() {
       register_post_type( 'product',
           array(
               'labels' => array(
               'name' => __( 'product' ),
               'singular_name' => __( 'product' ),
               'add_new' => __( 'Add New' ),
               'add_new_item' => __( 'Add new product' ),
               'edit' => __( 'Edit' ),
               'edit_item' => __( 'Edit product' ),
               'new_item' => __( 'New product' ),
               'view' => __( 'View product' ),
               'view_item' => __( 'View product' ),
               'search_items' => __( 'Search product' ),
               'not_found' => __( 'No product found' ),
               'not_found_in_trash' => __( 'No product found in Trash' )
               ),
               'public' => true,
               'show_ui' => true,
               'publicly_queryable' => true,
               'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields' ),
               'rewrite' => array("slug" => "product"),
               'taxonomies' => array('post_tag')
           )
       );
    }

This will create a post with the name 'product'. Then using the query_posts and the_permalink to get the link for single page and display the_content()

0

@ lps, thanks for your reply and it really show me some light in the darkness.
But how can we add price and date range for the product like this?
any help... thanks in advance.

0

try to use the custom fields that will only be available after you select it from the 'screen option' at your right top corner. But if you wish for a better user effect like a date picking tools etc, you should research on 'metabox' where you will be able to create your own layout for the extra fields.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.