<bdo id='pdAsR'></bdo><ul id='pdAsR'></ul>
<legend id='pdAsR'><style id='pdAsR'><dir id='pdAsR'><q id='pdAsR'></q></dir></style></legend>
  • <tfoot id='pdAsR'></tfoot>
  • <i id='pdAsR'><tr id='pdAsR'><dt id='pdAsR'><q id='pdAsR'><span id='pdAsR'><b id='pdAsR'><form id='pdAsR'><ins id='pdAsR'></ins><ul id='pdAsR'></ul><sub id='pdAsR'></sub></form><legend id='pdAsR'></legend><bdo id='pdAsR'><pre id='pdAsR'><center id='pdAsR'></center></pre></bdo></b><th id='pdAsR'></th></span></q></dt></tr></i><div id='pdAsR'><tfoot id='pdAsR'></tfoot><dl id='pdAsR'><fieldset id='pdAsR'></fieldset></dl></div>

      <small id='pdAsR'></small><noframes id='pdAsR'>

      1. 获取所有产品、类别和元数据的 SQL 查询 woocomm

        时间:2023-06-08
        <i id='SEqKA'><tr id='SEqKA'><dt id='SEqKA'><q id='SEqKA'><span id='SEqKA'><b id='SEqKA'><form id='SEqKA'><ins id='SEqKA'></ins><ul id='SEqKA'></ul><sub id='SEqKA'></sub></form><legend id='SEqKA'></legend><bdo id='SEqKA'><pre id='SEqKA'><center id='SEqKA'></center></pre></bdo></b><th id='SEqKA'></th></span></q></dt></tr></i><div id='SEqKA'><tfoot id='SEqKA'></tfoot><dl id='SEqKA'><fieldset id='SEqKA'></fieldset></dl></div>
      2. <small id='SEqKA'></small><noframes id='SEqKA'>

        1. <tfoot id='SEqKA'></tfoot>
            <bdo id='SEqKA'></bdo><ul id='SEqKA'></ul>

              <tbody id='SEqKA'></tbody>

              • <legend id='SEqKA'><style id='SEqKA'><dir id='SEqKA'><q id='SEqKA'></q></dir></style></legend>
                  本文介绍了获取所有产品、类别和元数据的 SQL 查询 woocommerce/wordpress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我一直在尝试创建一个返回参数的查询:

                  I'm stuck trying to create a query that returns me the parameters:

                  ID、post_title、post_content、类别、ID_category、SKU、名称、库存、价格

                  ID, post_title, post_content, category, ID_category, SKU, name, stock, price

                  此刻我有这个:

                  SELECT 
                   p.ID,
                   p.post_title,
                   `post_content`,
                   `post_excerpt`,
                   t.name AS product_category,
                   t.slug AS product_slug,
                   tt.term_taxonomy_id AS tt_term_taxonomia,
                   tr.term_taxonomy_id AS tr_term_taxonomia,
                   MAX(CASE WHEN pm1.meta_key = '_price' then pm1.meta_value ELSE NULL END) as price,
                   MAX(CASE WHEN pm1.meta_key = '_regular_price' then pm1.meta_value ELSE NULL END) as regular_price,
                   MAX(CASE WHEN pm1.meta_key = '_sale_price' then pm1.meta_value ELSE NULL END) as sale_price,
                   MAX(CASE WHEN pm1.meta_key = '_sku' then pm1.meta_value ELSE NULL END) as sku 
                  
                   FROM wp_posts p LEFT JOIN wp_postmeta pm1 ON ( pm1.post_id = p.ID)
                   LEFT JOIN   wp_term_relationships AS tr ON ( tr.object_id = p.ID )
                   LEFT JOIN   wp_term_taxonomy AS tt ON ( tt.taxonomy = 'product_cat' AND tr.object_id = tt.term_taxonomy_id)
                   LEFT JOIN   wp_terms AS t ON ( t.term_id = tt.term_id )
                   WHERE p.post_type in('product', 'product_variation') AND p.post_status = 'publish' AND p.post_content <> ''
                   GROUP BY p.ID,p.post_title
                  

                  它正确地为我提供了产品和元数据,但我很难在此查询中获得类别 ID 和类别名称,而且我无法在网上找到信息.

                  And it is giving me correctly the products and the metadata but it is very difficult for me to get the category ID and the category name in this query and I haven't been able to find information on the net.

                  谢谢.

                  推荐答案

                  您让 object_id 加入到 term_taxonomy_id 中,这毫无意义.

                  You had object_id joining to term_taxonomy_id which made no sense.

                  这就是我认为应该是这样的 -- 警告:我从来没有查询过 wp 数据库,只是查看了文档.

                  Here is how I think it should be -- caveat: I've never queried a wp database and was just going by the documentation.

                  SELECT 
                    p.ID,
                    p.post_title,
                    `post_content`,
                    `post_excerpt`,
                    t.name AS product_category,
                    t.term_id AS product_id,
                    t.slug AS product_slug,
                    tt.term_taxonomy_id AS tt_term_taxonomia,
                    tr.term_taxonomy_id AS tr_term_taxonomia,
                    MAX(CASE WHEN pm1.meta_key = '_price' then pm1.meta_value ELSE NULL END) as price,
                    MAX(CASE WHEN pm1.meta_key = '_regular_price' then pm1.meta_value ELSE NULL END) as regular_price,
                    MAX(CASE WHEN pm1.meta_key = '_sale_price' then pm1.meta_value ELSE NULL END) as sale_price,
                    MAX(CASE WHEN pm1.meta_key = '_sku' then pm1.meta_value ELSE NULL END) as sku 
                  FROM wp_posts p 
                  LEFT JOIN wp_postmeta pm1 ON pm1.post_id = p.ID
                  LEFT JOIN wp_term_relationships AS tr ON tr.object_id = p.ID
                  JOIN wp_term_taxonomy AS tt ON tt.taxonomy = 'product_cat' AND tt.term_taxonomy_id = tr.term_taxonomy_id 
                  JOIN wp_terms AS t ON t.term_id = tt.term_id
                  WHERE p.post_type in('product', 'product_variation') AND p.post_status = 'publish' AND p.post_content <> ''
                  GROUP BY p.ID,p.post_title
                  

                  这篇关于获取所有产品、类别和元数据的 SQL 查询 woocommerce/wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:我可以在不编写 SQL 查询的情况下找出数据库列表 下一篇:没有了

                  相关文章

                  最新文章

                  <small id='QADZS'></small><noframes id='QADZS'>

                    • <bdo id='QADZS'></bdo><ul id='QADZS'></ul>
                    <i id='QADZS'><tr id='QADZS'><dt id='QADZS'><q id='QADZS'><span id='QADZS'><b id='QADZS'><form id='QADZS'><ins id='QADZS'></ins><ul id='QADZS'></ul><sub id='QADZS'></sub></form><legend id='QADZS'></legend><bdo id='QADZS'><pre id='QADZS'><center id='QADZS'></center></pre></bdo></b><th id='QADZS'></th></span></q></dt></tr></i><div id='QADZS'><tfoot id='QADZS'></tfoot><dl id='QADZS'><fieldset id='QADZS'></fieldset></dl></div>

                    <legend id='QADZS'><style id='QADZS'><dir id='QADZS'><q id='QADZS'></q></dir></style></legend>

                    1. <tfoot id='QADZS'></tfoot>