如果使用自定义字段满足三个条件,我正在尝试使用wordpress发布最新帖子。首先,河流必须是“科罗拉多”,区域必须是“区域4”,位置必须是“声音5”。这甚至可以吗?
到目前为止代码:
<?php $querystr = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = 'select_river'
AND wpostmeta.meta_value = 'Colorado'
AND wpostmeta.meta_key = 'select_area'
AND wpostmeta.meta_value = 'Area 4'
AND wpostmeta.meta_key = 'select_soundbite_position'
AND wpostmeta.meta_value = 'soundbite 5'
AND wposts.post_status = 'publish'
AND wposts.post_type = 'post'
ORDER BY wposts.post_date DESC
";
$pageposts = $wpdb->get_results($querystr, OBJECT);
if ($pageposts):
foreach ($pageposts as $post):
setup_postdata($post); ?>
<p>Test</p>
<?php endforeach; ?>
<?php endif; ?>
它不起作用,我不知道为什么......我对PHP的理解缺乏
答案 0 :(得分:0)
那是怎么回事:
<?php
$querystr = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta, $wpdb->postmeta wpostmeta2, $wpdb->postmeta wpostmeta3
WHERE wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = 'select_river'
AND wpostmeta.meta_value = 'Colorado'
AND wpostmeta2.meta_key = 'select_area'
AND wpostmeta2.meta_value = 'Area 4'
AND wpostmeta3.meta_key = 'select_soundbite_position'
AND wpostmeta3.meta_value = 'soundbite 5'
AND wposts.post_status = 'publish'
AND wposts.post_type = 'post'
ORDER BY wposts.post_date DESC
";
?>