Mysql
 sql >> Cơ Sở Dữ Liệu >  >> RDS >> Mysql

Truy vấn SQL để kiểm tra product_type trong WooCommerce

Truy vấn MySQL để liệt kê tất cả Sản phẩm đơn giản :

SELECT
    posts.ID,
    posts.post_title,
    posts.post_author,
    posts.post_date,
    posts.post_date_gmt,
    posts.post_content,
    posts.post_excerpt,
    posts.post_status,
    posts.comment_status,
    posts.ping_status,
    posts.post_password,
    posts.post_name,
    posts.to_ping,
    posts.pinged,
    posts.post_modified,
    posts.post_modified_gmt,
    posts.post_content_filtered,
    posts.post_parent,
    posts.guid,
    posts.menu_order,
    posts.post_type,
    posts.post_mime_type,
    posts.comment_count
FROM
    wp_posts AS posts
INNER JOIN wp_term_relationships AS term_relationships ON posts.ID = term_relationships.object_id
INNER JOIN wp_term_taxonomy AS term_taxonomy ON term_relationships.term_taxonomy_id = term_taxonomy.term_taxonomy_id
INNER JOIN wp_terms AS terms ON term_taxonomy.term_id = terms.term_id
WHERE
    term_taxonomy.taxonomy = 'product_type'
AND terms.slug = 'simple'
AND posts.post_type = 'product';

Chỉ cần thay thế simple từ AND terms.slug = 'simple' dòng với biến variable để nhận tất cả Sản phẩm có thể thay đổi ;

Tôi đã kiểm tra truy vấn SQL này và nó đang hiển thị kết quả chính xác.

Hy vọng điều này sẽ hữu ích!




  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Echo / return đang thêm khoảng trắng trước biến

  2. Cách chuyển giá trị cơ sở dữ liệu trong siêu liên kết bằng PHP + HTML

  3. MySQL 8 Biểu thức Bảng Phổ biến CTE

  4. Định cấu hình nhóm kết nối GlassFish JDBC để xử lý chuyển đổi dự phòng Amazon RDS Multi-AZ

  5. Ngăn chặn đầu ra cảnh báo trong bash