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