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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀