dongshun5963 2014-01-08 10:15
浏览 29
已采纳

使用自定义元日期显示自定义帖子类型,但在WP中保留日程安排功能

I have a custom post type that displays depending on the custom post date (an event date) but now I cannot use the WordPress scheduling that is built in because posts show in relation to a custom meta date provided in the post.

Is there a way to add an argument into my array to check the post date so that it only displays the custom post if the post date has passed?

Here is my current code that does exactly as needed

$today = date('Y-m-d');
            $args = array( 
                   'post' => 'ID', 
                   'post_type' => 'foodswaps', 
                   'posts_per_page' => 3, 
                   'meta_key' => '00.event-date',
                   'meta_value' => $today,
                   'meta_compare' => '>=',
                   'orderby' => 'meta_value',
                   'order' => 'ASC' 
            );

I have spent the last day looking for an answer but haven't found anything or any similar cases so any pointers and directional nudges would be appreciated!

  • 写回答

1条回答 默认 最新

  • duandao7704 2014-01-08 10:29
    关注

    Try adding:

    'post_status' => 'publish',

    E.g.

    $today = date('Y-m-d');
                $args = array( 
                       'post' => 'ID', 
                       'post_type' => 'foodswaps', 
                       'posts_per_page' => 3, 
                       'post_status' => 'publish', //  <-----------
                       'meta_key' => '00.event-date',
                       'meta_value' => $today,
                       'meta_compare' => '>=',
                       'orderby' => 'meta_value',
                       'order' => 'ASC' 
                );
    

    That should then show only posts with the status published.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程