如果自定义字段为 true,则显示最新帖子
我试图让 WordPress 仅在使用自定义字段满足三个条件时才发布最新帖子。首先,河流必须是“Colorado”,区域必须是“Area 4”,位置必须是“soundbite 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 的理解缺乏
I am trying to get a wordpress to post a latest post only if three conditions are met using custom fields. First the river has to be the 'Colorado', Area has to be 'Area 4' and position has to be 'soundbite 5'. Is this even possible to do?
Code so far:
<?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; ?>
It doesn't work and I have no idea why... well my understanding of PHP is lacking
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那又怎么样:
What about that: