• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Custom blog page returns 404 on pagination link click

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Custom blog page returns 404 on pagination link click

This topic is: not resolved

Tagged: 404, loop, pagination

  • This topic has 1 reply, 2 voices, and was last updated 6 years, 5 months ago by Victor Font.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • December 22, 2016 at 2:32 pm #198013
    aschoenbrun
    Member

    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 #198286
    Victor Font
    Moderator

    It'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?

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble