Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have created custom template page like this with a custom query on page showing only details fetch from my custom table not any post.

/*

Template Name:product

*/
<?php get_header(); ?>
<?php

    $data = $wpdb->get_results("myquery Here");
    foreach($data as $row)
    {
        product Name:  $row->p_name;
        prod price: $row->p_price;
?>
    <a href="">VIEW PRODUCT</a>

<?php
    }
?>
<?php get_footer();?>

I need help about when we click on "VIEW PRODUCT" then how can I redirect to next view_detail page?

For that can I create another *view_detail.php* page? What should I write on href="" with passing product_id, which I get on view_detail.php.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted
<?php
/*
Template Name:product
*/

get_header();

// check if product_id is not set or is empty string
if( !isset($_GET['product_id']) || '' == $_GET['product_id'] ) {
    // if so, run your query and display data
    $data = $wpdb->get_results("myquery Here");
    foreach($data as $row) {
        echo '<div>';
        echo '<p>Name:' . $row->p_name . '</p>';
        echo '<p>Price:' . $row->p_price. '</p>';
        // pass ID using GET
        echo '<p><a href="?product_id=' . $row->p_id . '">VIEW PRODUCT</a></p>';
        echo '</div>';
    }
}
else {
    // product_id is set and is not empty
    require('/path/to/view_detail.php');
}

get_footer();
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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