dove2199 2013-06-27 09:02
浏览 18
已采纳

Wordpress - 管理活动列表?

I have an events page that uses the following query:

<?php $portfolioloop = new WP_Query( array( 'post__not_in' => array(4269), 'paged' => get_query_var('paged'), 'post_status' => 'future', 'post_type' => 'whatson', 'exclude' => '4269', 'posts_per_page' => 20, 'order' => 'ASC')); ?>

All this does is show a list of all scheduled custom posts and when the post hits the scheduled date it publishes the page... thus removing it from the list.

It's nearly what I want, when it hits the publish date, the event is actually running on that day so removing it from the list isn't quite correct.

Is there a way I can delay removing it from the list until the end of the day?

p.s I don't want to use a plugin as I don't think it warrants it.


I've found this:

$args = array(
   'posts_per_page' => 3,
   'meta_key' => 'event-start-date',
   'orderby' => 'meta_value',
   'order' => 'ASC',
   'meta_query' => array(
      array( 'key' => 'event-end-date', 'compare' => '>=', 'value' => date('Y-m-d') )
   )
);
query_posts($args);

I don't want to sort by a custom field so how can I do it by the post publish date?

  • 写回答

2条回答 默认 最新

  • duanjizi9443 2013-07-03 15:30
    关注

    Finally solved this with:

    function my_filter_where( $where = '' ) {
        global $wp_query;
        if (is_array($wp_query->query_vars['post_status'])) {
    
            if (in_array('future',$wp_query->query_vars['post_status'])) {
            // posts today into the future
            $where .= " AND post_date > '" . date('Y-m-d', strtotime('now')) . "'";
            }
        }
        return $where;
    }
    add_filter( 'posts_where', 'my_filter_where' );
    

    And:

    <?php
    $wp_query = array(
            'post__not_in' => array(4269),
            'paged' => get_query_var('paged'),
            'post_type' => 'whatson',
            'exclude' => '4269',
            'posts_per_page' => 20,
            'order' => 'ASC',
            'orderby' => 'date',
            'post_status' =>array('future','published'));
    query_posts($wp_query);
    ?>
    
                        <?php 
                        if ($wp_query->have_posts()) {
                        while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
                            Content
                        <?php endwhile; // end of the loop.
                        }  ?>
    
                        <?php if (function_exists('wp_pagenavi')) { wp_pagenavi( array( 'query' => $wp_query ) ); } ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?