To select WooCommerce product with most product tags, you need to join several WordPress database tables:
wp_posts (for product information), wp_term_relationships (to link products to terms), wp_term_taxonomy (to define the taxonomy, in this case, ‘product_tag’), and wp_terms (for the actual tag names).Here is the SQL query:
Code
SELECT p.ID AS product_id, p.post_title AS product_name, COUNT(tr.term_taxonomy_id) AS tag_countFROM wp_posts AS pINNER JOIN wp_term_relationships AS tr ON p.ID = tr.object_idINNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_idWHERE p.post_type = 'product' AND p.post_status = 'publish' AND tt.taxonomy = 'product_tag'GROUP BY p.ID, p.post_titleORDER BY tag_count DESCLIMIT 1;

Bài viết cùng chuyên mục, chủ đề