0

I have inserted values product-price, name and size in wordpress. The insert code is below

function products_save_postdata($post_id) {
  if (isset ($_POST['price'])) {
    update_post_meta($post_id, 'price', esc_attr($_POST['price']));
  }
  if (isset ($_POST['product_name'])) {
    update_post_meta($post_id, 'product_name', esc_attr($_POST['product_name']));
  }
  if (isset ($_POST['size'])) {
    update_post_meta($post_id, 'size', esc_attr($_POST['size']));
  }
}

How can i fetch this inserted data?

0
<?php
$args = array('post_type'=>'products','posts_per_page'=>10,'number_posts'=>10);
$products = get_posts($args);

foreach($products as $product) {

$productid = $product->ID;

 echo $producttitle = $product->post_title;

echo $productdescription = $product->post_content;

echo get_post_meta($productid ,'price', TRUE);

echo get_post_meta($productid ,'product_name', TRUE);

echo get_post_meta($productid ,'size', TRUE);

}
?>

if the value is empty it shows null otherwise

  • Thnx. But i want to create a list which i have inserted. – Bikash Mondal Aug 22 '13 at 7:21
  • didn't understand can u explain in more details – Balas Aug 22 '13 at 7:22
  • I have inserted 10 products with its details in admin part. I want to display a list of these products in user part means in front end. – Bikash Mondal Aug 22 '13 at 7:24
  • i have edited my code – Balas Aug 22 '13 at 7:28
  • it shows "Hello world!Welcome to WordPress. This is your first post. Edit or delete it, then start blogging! " – Bikash Mondal Aug 22 '13 at 7:31

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.