2
我需要帮助来开发wordpress定制。我有以下MySQL查询与UNION
指令:Mysql UNION on wordpress
SELECT
wp_posts.*
FROM wp_posts
INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
LEFT JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id AND mt1.meta_key = 'dir_featured')
WHERE
(wp_term_relationships.term_taxonomy_id IN (2151)) AND
wp_posts.post_type = 'ait-dir-item' AND
((wp_posts.post_status = 'publish')) AND
(
(
wp_postmeta.meta_key = 'dir_featured' AND
CAST(wp_postmeta.meta_value AS CHAR) = 'yes'
)
)
GROUP BY wp_posts.ID
UNION
SELECT
wp_posts.*
FROM wp_posts
INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
LEFT JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id AND mt1.meta_key = 'dir_featured')
WHERE
wp_term_relationships.term_taxonomy_id IN (2151) AND
wp_posts.post_type = 'ait-dir-item' AND
wp_posts.post_status = 'publish' AND
mt1.post_id IS NULL
GROUP BY wp_posts.ID
我想把这个查询与WordPress参数转化。可能吗?
你是什么意思“翻译此查询与wordpress参数”?你能澄清一下吗? – Epodax 2015-03-31 12:57:42
我打算把它与WordPress的参数写入作为该样品 \t $ PARAMS =阵列( \t \t 'post_type' \t \t \t> 'AIT-DIR-项', \t \t 'nopaging' \t \t \t => \t真, \t \t 'meta_query'=>数组( \t \t \t '关系'=> 'OR', \t \t \t \t阵列( \t \t \t \t \t '键'=> 'dir_featured', \t \t \t \t \t '值'=> '是', \t \t \t \t \t '比较'=> '=' \t \t \t \t) \t \t \t \t阵列( \t \t \t \t \t '键'=> 'dir_featured', \t \t \t \t \t '值'=> '', \t \t \t \t \t '比较'=> 'NOT EXISTS' \t \t \t \t) \t \t \t)\t, \t \t '的OrderBy' \t \t \t => ARR AY( 'dir_featured'=> 'DESC', 'POST_DATE'=> 'ASC'), \t \t 'post_status' \t \t => '发布', \t \t 'tag__in' \t \t \t => $ queried_object - > term_id \t); – PuroSangueZ 2015-03-31 13:58:40
当你需要wp_postmeta的记录时,为什么你要使用左连接到wp_postmeta?为什么在第一个查询中没有使用wp_meta的第二个实例时,会出现LEFT JOIN? – symcbean 2015-03-31 14:04:27