Community Forums › Forums › Archived Forums › General Discussion › Custom blog page returns 404 on pagination link click
Tagged: 404, loop, pagination
- This topic has 1 reply, 2 voices, and was last updated 7 years, 8 months ago by Victor Font.
-
AuthorPosts
-
December 22, 2016 at 2:32 pm #198013aschoenbrunMember
have been researching this for a while, looking over quite a few stackexchange posts. This seems to be a relatively common problem, but the more common solutions do not seem to work while others seem complicated and are hard to follow. I have a WordPress site using the Genesis framework. I have a static home page and have set up a custom page for the blog. My issue is with pagination. Whether using the WP PageNavi plugin (preferred) or Genesis' native pagination, when I click on the page links I get a 404. Pagination on category pages works fine. Please note: I do have other custom post types used in other parts of the site. I do not need to call them here. I just need the regular "post" type posts.
My site is http://youreffectivemedia.com/ and the blog page is at http://youreffectivemedia.com/blog/ (dont mind the fake tesing posts 🙂 )
Code for custom loop:
// Define custom query parameters $args = array( 'post_type' => '', 'posts_per_page' => 10 ); // Get current page and append to custom query parameters array $args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; // Instantiate custom query $query = new WP_Query( $args ); // Pagination fix $temp_query = $wp_query; $wp_query = NULL; $wp_query = $query; if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); echo '<article id="post-' . get_the_ID() . '" ' . get_post_class('BlogPost BlogArticle') . '>'; include(locate_template('partials/template_part-single_header.php')); echo '<a class="ArchiveViewButton" href="' . get_the_permalink() . '"><button>View</button></a>'; echo '</article>'; endwhile; endif; wp_reset_postdata(); wp_pagenavi( array( 'query' => $query ) ); // Reset main query object $wp_query = NULL; $wp_query = $temp_query;
The template part "template_part-single_header" works as it should. I do not think it is of consequence here because it does not involve setting up the loop query.
I did play with the "paged" declaration as well as "pre_get_posts" to no avail.
Any help or direction would be greatly appreciated. Thank you very much.
http://youreffectivemedia.com/blog/December 27, 2016 at 9:07 am #198286Victor FontModeratorIt's really hard to say without debugging your code. I would use a plugin like this one https://wordpress.org/plugins/kint-php-debugger/ to view the array content while executing the loop. Also, not sure why you are double assigning $wp_query first to null, then to a value. You may also need to consider moving wp_reset_postdata to the end of the loop. You may be resetting things too early.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet? -
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.