【发布时间】:2016-07-29 22:57:03
【问题描述】:
我正在使用 wordpress,并且有一个自定义帖子类型的自定义存档页面。 自定义循环获取登录用户的注册日期,并且仅显示在注册时或注册后发布的帖子。效果很好。
但是,分页仍在使用主查询,因此如果总共有 4 个帖子设置为每页 2 个帖子,则分页始终显示有两个页面,即使由于登录用户注册日期而只显示一个帖子.
谁能帮我修改我所拥有的内容,以便分页只显示该用户查询的超过 2 个帖子的结果?我已经尝试了几个小时,使用我在网络上找到的各种更改...
<?php if ( have_posts() ): ?>
<?php
# Get the current user's info
$user_info = get_userdata(get_current_user_id());
# Use date_parse to cast your date to an array
$regdate = date_parse($user_info->user_registered);
# Set your arguments for WP Query
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'inner',
'posts_per_page' => '2',
'posts_per_archive_page' => '2',
'paged' => $paged,
'date_query' => array(
array(
'after' => array(
# Setting date to array above allows to call specific values within that date
'year' => $regdate['year'],
'month' => $regdate['month'],
'day' => $regdate['day'],
),
# Include posts from the day the user registered
'inclusive' => true,
),
),
# Display all posts on a single page.
);
$my_query = new WP_Query( $args );
while ($my_query->have_posts()) : $my_query->the_post();
get_template_part( 'template-parts/content', get_post_format() );
endwhile; ?>
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
<?php else: ?>
Nada
<?php endif; ?>
【问题讨论】:
标签: wordpress loops pagination custom-post-type archive