我试图选择帖子标题和两个元素值。但我无法得到正确的查询.Y查询粘贴在下面请帮助。
$querystr = "
SELECT $wpdb->posts.post_title
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->postmeta.meta_key = side_post_meta_id
AND $wpdb->postmeta.meta_value LIKE %".$search_term."%
AND $wpdb->postmeta.meta_key = side_post_id
AND $wpdb->postmeta.meta_value LIKE %".$cat_find."%
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'post'
ORDER BY $wpdb->posts.post_date DESC LIMIT 0,10
";
print_r($querystr);
$pageposts = $wpdb->get_results($querystr, OBJECT);
答案 0 :(得分:0)
请尝试这样的事情......
<?php
global $wpdb;
$get_results= $wpdb->get_results( "SELECT p.post_title, pm2.meta_value , pm3.meta_value
FROM wp_posts as p
INNER JOIN wp_postmeta AS pm1 ON pm1 .post_id = p.ID
INNER JOIN wp_postmeta AS pm2 ON pm2 .post_id = p.ID AND pm2.meta_key='side_post_meta_id' AND pm2.meta_value like '%$search_term%'
INNER JOIN wp_postmeta AS pm3 ON pm3 .post_id = p.ID AND pm3 .meta_key='side_post_id' AND pm3 .meta_value like '%$cat_find%'
WHERE p.post_status = 'publish' AND p.post_type = 'post' ORDER BY p.post_date DESC LIMIT 0,10");
echo '<pre>';
print_r($get_results);
echo '</pre>';