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.

Recommended Answers

All 3 Replies

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',
               '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()

@ 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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.