dqmdlo9674 2015-07-23 13:16 采纳率: 100%
浏览 71
已采纳

如何使用mysql -php根据category_id检索woocommerce产品详细信息

I have to retrieve the product details such as image title,description,image link and price from woocommerce table.

I've retrieved the categories with this Query,

$result = mysql_query("SELECT term_id,name,slug FROM wp_terms WHERE term_id 
    IN (SELECT term_id FROM wp_term_taxonomy WHERE parent='0' 
    AND taxonomy='product_cat') ORDER BY name ASC");

Based on this category id I'm retrieving the subcategories like this:

  $result = mysql_query("SELECT term_id,name,slug FROM wp_terms WHERE term_id
     IN (SELECT term_id FROM wp_term_taxonomy WHERE parent='$cat_id'
     AND taxonomy='product_cat') ORDER BY name ASC");

I've tried a query to get the product details,

 $result = mysql_query("SELECT  `ID`,`post_title`,`post_content`,`guid` FROM wp_posts WHERE
post_type='product' and post_status='publish' and ID IN(SELECT object_id
FROM wp_term_relationships WHERE term_taxonomy_id IN('$cat_id') and 
term_taxonomy_id IN(SELECT term_taxonomy_id FROM wp_term_taxonomy 
where taxonomy='product_cat'))");

This is giving me the title and description when I execute it in phpmyadmin but when I give the same code in php and sending the response through json then it is giving me the empty response.

I think my query is not proper.

Kindly suggest me how to get the product details from woocommerce,am working with it for the first time.

  • 写回答

3条回答 默认 最新

  • douying1119 2015-07-24 13:42
    关注

    At last I've DONE IT

    Here goes the procedure of steps:

        --->  get `id` of product from `wp_posts`
        --->  pass it as a `post_id` to `wp_postmeta` and get the `meta_value` where `meta_key`='_thumbnail_id'
        --->  now send this `meta_value` as `id` of the product to `wp_posts `
        --->  in the field `guid` we have the link of image of the product
    

    To get the price of the product:

    ---> Send `id` as a `post_id` to `wp_postmeta` and get the `meta_value` where `meta_key`='_price'
    

    Product description and product title are stored in the table wp_posts in the fields post_title and post_excerpt respectively.

    I've executed all these queries separately. That's why I'm not adding them in this answer.I'll edit this answer once am done with joins

    Happy coding.. :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算