如果自定义字段为 true,则显示最新帖子

发布于 2024-10-16 00:32:01 字数 998 浏览 2 评论 0原文

我试图让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沉鱼一梦 2024-10-23 00:32:01

那又怎么样:

<?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
      ";
?>

What about that:

<?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
      ";
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文