Home wordpress custom post type pagination page 2 not found
Reply: 1

wordpress custom post type pagination page 2 not found

Abd Hannan
1#
Abd Hannan Published in 2018-01-13 03:53:21Z

Can anyone help me, i have custom post type created with CPT UI plugin, i will add pagination like this: This is my code on my custom template page:

<div class="row">
				<?php
				/**
				 * @package Momentum
				 * Loop custom post type (journal)
				 * @see https://codex.wordpress.org/Post_Types
				 */

				/**
				 * Pagination
				 * @see https://stackoverflow.com/questions/41738362/how-to-include-pagination-in-a-wordpress-custom-post-type-query
				 */
				$paged = (get_query_var( 'paged' )) ? get_query_var( 'paged' ) : 1;

				$args = array(
					'post_type'      => 'journal',
					'showposts'		 => 2,
					'posts_per_page' => 2,
					'order'          => 'DESC',
					'paged'          => $paged,
				);
				$loop = new WP_Query($args);
				if ($loop->have_posts()):
					while ($loop->have_posts()) : $loop->the_post();
				?>
				<div class="col-lg-6 content">
					<div class="article">
						<div class="image">
							<?php
							/**
							 * @package Momentum
							 * Check the featured image
							 * @see https://codex.wordpress.org/Post_Thumbnails
							 */
							if (has_post_thumbnail()) {
								the_post_thumbnail( 'full', array('class' => 'img-responsiv') );
							}else { ?>
								<img src="<?php echo get_template_directory_uri(); ?>/assets/img/journal-1.jpg" alt="journal">
							<?php
							}
							?>
							
						</div>
						<div class="text-content">
							<div class="head-content">
								<div class="title">
									<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
								</div>
								<div class="excerpt">
									<?php the_excerpt(); ?>
								</div>
							</div>
							<div class="footer">
								<a href="<?php the_permalink(); ?>" class="read-more pull-left">READ ENTRY</a>
								<span class="date pull-right"><?php echo get_the_date(); ?></span>
							</div>
						</div>
					</div>
				</div><!-- /.col-lg-6 -->
					<?php endwhile; ?>

					<?php
					$total_pages = $loop->max_num_pages;
					if ($total_pages > 1) {
						$current_page = max(1, get_query_var( 'paged' ));
						echo paginate_links( array(
							'base' => get_pagenum_link( 1 ) . '%_%',
							'format' => 'page/%#%',
							'current' => $current_page,
							'total' => $total_pages,
							'prev_text' => __('PREVIOUS'),
							'next_text' => __('NEXT'),
						) );
					}
					?>

				<?php else: ?>
					<h1>No Journal found</h1>
				<?php endif; ?>
				<?php wp_reset_postdata(); ?>
			</div>

The pagination link work fine /page/2/...

The problem, when clicked to page/2 the page not found.

I have tried all answear and question on stackoverflow, but not work.

Abd Hannan
2#
Abd Hannan Reply to 2018-01-13 05:20:47Z

Finally, fixed the issue when changed has_archive from false to true. I use CPT UI plugin

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.32417 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO