Я пытаюсь сделать оптимизированный запрос для экспорта товаров с сайта woocommerce. То, чего я пытаюсь достичь, - это указать термин и мета-значение в одной строке с продуктом, но у меня странные ошибки. Запрос, который я до сих пор достиг, это
SELECT p.*, t.name brand, pm_ss.meta_value stock_status
FROM wp_posts as p, wp_term_relationships as r, wp_terms as t
LEFT JOIN wp_term_taxonomy as x ON x.term_id=t.term_id AND x.taxonomy='product_brand'
LEFT JOIN wp_postmeta AS pm_ss ON pm_ss.post_id=p.ID AND pm_ss.meta_key='_stock_status'
WHERE p.post_status = 'publish' AND p.post_type = 'product'
AND r.term_taxonomy_id=x.term_taxonomy_id AND pm_ss.meta_value!='outofstock'
, но я получаю эту ошибку:
unknown column 'p.id' in on clause
, хотя, очевидно, имя столбца верное. Поскольку это также общая проблема c, я добавляю некоторую информацию для тех, кто не знаком со структурой таблиц WordPress. Основная таблица - wp_posts
, в которой в качестве идентификатора используется столбец ID
. Тогда есть другие таблицы:
TABLE wp_posts
ID : identifier of the table
post_content : content of the post
post_title : title of the post
post_type : type of the post
post_status : status of the post
... other column not useful for the question
TABLE: wp_postmeta - contains all post meta
post_id : refers to wp_posts.ID
meta_key : identifier of the meta tag
meta_value : value of the meta tag
TABLE: wp_terms - contains all terms
term_id : identifier of the term
name : name of the term, in this case it contains the brand name
TABLE: wp_term_relationships - contains link between terms and posts
object_id : refers to wp_posts.ID
term_taxonomy_id : refers to wp_terms.terms_id
TABLE: wp_term_taxonomy - contains the description of the specific term
term_id : refers to wp_terms.terms_id
taxonomy : specify the use of the specific term, in this case i'm looking for product_brand
Кроме того, у кого-то есть сведения о том, как улучшить запрос и, возможно, выполнить поиск по двум различным типам терминов в одном запросе? Спасибо