I'm using wordpress and have a custom archive page for a custom post type. The custom loop gets the logged in users registration date and only shows posts that were published on or after they registered. Works great.
However, the pagination is still using the main query so if there are 4 posts in total set to 2 posts per page the pagination always shows there are two pages even if only one post is displayed due to the logged in users registered date.
Can anyone help me modify what I have so the pagination only shows for results in more than 2 posts for that users query? I've been trying for hours now using various changes I've found on the web...
<?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; ?>