0

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.

1
<?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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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