Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 张贴一周_Wordpress_Custom Fields - Fatal编程技术网

Wordpress 张贴一周

Wordpress 张贴一周,wordpress,custom-fields,Wordpress,Custom Fields,有人能帮我展示这篇文章一周吗?我有这样的代码,在post_date中运行良好: <?php $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'cat' => 1, 'orderby' => 'date', 'order' => 'DESC', // Using the date_query to filter posts fr

有人能帮我展示这篇文章一周吗?我有这样的代码,在post_date中运行良好:

<?php
  $args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'cat' => 1,
    'orderby' => 'date',
    'order' => 'DESC',
    // Using the date_query to filter posts from last week
    'date_query' => array(
      array(
        'after' => '1 week ago'
      )
    )
  ); 
?>
<ul class="weekly-list">
    <?php $the_query = new WP_Query( $args ); ?>
    <?php while ( $the_query->have_posts() ) { $the_query->the_post(); ?>
    <li>
        <a href="<?php the_permalink(); ?>">
            <?php the_title(); ?>
        </a>
    </li>
    <?php } wp_reset_postdata(); ?>
</ul>

但是如何在自定义字段date中执行此操作。因为我的其他活动是在活动前一周发布的。有人能帮我吗


谢谢。

这可能会帮助您获得解决方案:

 $week = date('W');
 $year = date('Y');
 $the_query = new WP_Query( 'year=' . $year . '&w=' . $week );
  if ( $the_query->have_posts() ) : 
    while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
            <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?> "><?php the_title(); ?></a></h2>
            <?php the_excerpt(); ?>
        <?php endwhile; ?>
        <?php wp_reset_postdata(); ?>
    <?php else:  ?>
            <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>
$week=日期('W');
$year=日期('Y');
$the_query=new WP_query('year='.$year.&w='.$week);
如果($the\u query->have\u posts()):
while($the_query->have_posts()):$the_query->the_post();?>


这可能有助于您获得解决方案:

 $week = date('W');
 $year = date('Y');
 $the_query = new WP_Query( 'year=' . $year . '&w=' . $week );
  if ( $the_query->have_posts() ) : 
    while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
            <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?> "><?php the_title(); ?></a></h2>
            <?php the_excerpt(); ?>
        <?php endwhile; ?>
        <?php wp_reset_postdata(); ?>
    <?php else:  ?>
            <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>
$week=日期('W');
$year=日期('Y');
$the_query=new WP_query('year='.$year.&w='.$week);
如果($the\u query->have\u posts()):
while($the_query->have_posts()):$the_query->the_post();?>


前面的答案是正确的。只需修改您的
日期\u查询

<?php
  $args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'cat' => 1,
    'orderby' => 'date',
    'order' => 'DESC',
    // Using the date_query to filter posts from last week
    'date_query' => array(
        array(
            'year' => date( 'Y' ),
            'week' => date( 'W' ),
        ),
    ),
  );
?>
<ul class="weekly-list">
    <?php $the_query = new WP_Query( $args ); ?>
    <?php while ( $the_query->have_posts() ) { $the_query->the_post(); ?>
    <li>
        <a href="<?php the_permalink(); ?>">
            <?php the_title(); ?>
        </a>
    </li>
    <?php } wp_reset_postdata(); ?>
</ul>


前面的答案是正确的。只需修改您的
日期\u查询

<?php
  $args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'cat' => 1,
    'orderby' => 'date',
    'order' => 'DESC',
    // Using the date_query to filter posts from last week
    'date_query' => array(
        array(
            'year' => date( 'Y' ),
            'week' => date( 'W' ),
        ),
    ),
  );
?>
<ul class="weekly-list">
    <?php $the_query = new WP_Query( $args ); ?>
    <?php while ( $the_query->have_posts() ) { $the_query->the_post(); ?>
    <li>
        <a href="<?php the_permalink(); ?>">
            <?php the_title(); ?>
        </a>
    </li>
    <?php } wp_reset_postdata(); ?>
</ul>


如何插入事件的CU日期自定义字段?如何插入事件的CU日期自定义字段?如何在日期查询中插入事件的CU日期自定义字段?是否正确$customDate=get_post_meta($post->ID,'c_date',true);'年“=>date('Y',strotime($customDate)),'week'=>date('W',strotime($customDate)),但是您只能在循环中获取post meta,如何获取post ID以便在查询参数中使用?我也不知道你到底希望通过这个实现什么?上面的查询将只显示上周的帖子,仅此而已。我正在尝试查询本周的帖子,但如果我在事件发生前1周发布的帖子,我会感到困惑。所以我为这个定制了一个日期“c_date”。例如,该活动适用于3月的第一周。所以现在它不会只在本周显示,如果三月临近,它会显示。检查并发布。特别是第二个,它讨论了包含日期…我将如何在日期查询中插入事件的c_日期自定义字段?这是否正确$customDate=get_post_meta($post->ID,'c_date',true);'年“=>date('Y',strotime($customDate)),'week'=>date('W',strotime($customDate)),但是您只能在循环中获取post meta,如何获取post ID以便在查询参数中使用?我也不知道你到底希望通过这个实现什么?上面的查询将只显示上周的帖子,仅此而已。我正在尝试查询本周的帖子,但如果我在事件发生前1周发布的帖子,我会感到困惑。所以我为这个定制了一个日期“c_date”。例如,该活动适用于3月的第一周。所以现在它不会只在本周显示,如果三月临近,它会显示。检查并发布。特别是第二个,它谈到了包容性的日期。。。