• Resolved Andrew Ledwith

    (@jaledwith)


    First off, the website I’m referring to is http://floridanavs.org/blog/.

    I’m creating a loop for this blog that includes multiple post types. All the following code is within home.php (rather than index.php).

    query_posts( array(
         		'post_type' => array( 'post', 'flnavs_podcast', 'flnavs_video', 'flnavs_resources' ) )
    	 		);
    			if ( have_posts() ) : $count = 0;
    				while ( have_posts() ) : the_post(); $count++;
    					get_template_part( 'loop', get_post_format() );
    				endwhile;
    			else: ?>
    				<div class="post">
    					<h2 class="title">
    						<?php _e('Sorry!','standardtheme'); ?>
    					</h2>
    					<p>
    						<?php _e('Whoops! Something broke. Please try again!','standardtheme'); ?>
    					</p>
    				</div>
    			<?php endif;
    			// Function that handles output of pagination
    			standard_pagination(); ?>

    This loop will successfully display the first 10 posts (as defined in the Reading panel in Settings) but when I click on Older Posts I get a 404 error. I’ve tried using WP_Query instead of query_posts but the same error occurs. Any idea what’s going wrong?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Try replacing:

    query_posts( array(
         		'post_type' => array( 'post', 'flnavs_podcast', 'flnavs_video', 'flnavs_resources' ) )
    	 		);

    with:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'post_type' => array( 'post', 'flnavs_podcast', 'flnavs_video', 'flnavs_resources' ),
    	'paged' => $paged
    );
    query_posts($args);
    Thread Starter Andrew Ledwith

    (@jaledwith)

    Thanks for your reply. Unfortunately that didn’t fix the problem. I should have mentioned that I’d tried that solution before. Perhaps it’s needed in the final product but something else is missing too.

    Have you tried looking at the standard_pagination() function?

    Thread Starter Andrew Ledwith

    (@jaledwith)

    Yes. It looks pretty innocuous. It also performs just fine on other archive pages (category, author, etc.).

    function standard_pagination() { ?>
    		<div class="more_entries">
            	<div class="next-posts fl"><?php next_posts_link('&laquo; Older Posts') ?></div>
    		<div class="prev-posts fr"><?php previous_posts_link('Newer Posts &raquo;') ?></div>
    		</div>
    <?php } ?>

    What happens if you remove the custom query in home.php?

    Thread Starter Andrew Ledwith

    (@jaledwith)

    Well, there are only 9 posts in the default post type, but after adjusting the settings panel to display 5 posts per page both the blog and first archive page render properly.

    So it sounds like there’s a problem with your custom post types. Check that you have the correct names in that custom query

    Thread Starter Andrew Ledwith

    (@jaledwith)

    The names are correct. I used the $post_type parameter I defined for each custom post type. I’ve had no problem getting each post type to appear on the first page of the blog, so I know I’ve gotten the names correct all this time.

    I just stumbled across something really strange. Like I said, I altered the number of posts per page from 10 to 5. I tried going to the second page of the blog using those settings and it loaded successfully. But then I tried to go to the third page and I received a 404. Just to test things further I switched the posts per page from 5 to 3. I can load the first, second, and third pages of the blog, then I receive a 404 when I try to load the fourth. So, I can load no more than 10 posts, and it’ll load fewer than that if the display setting doesn’t divide evenly into ten.

    I’m completely baffled now.

    Have you tried:

    – deactivating all plugins to see if this resolves the problem. If this works, re-activate the plugins one by one until you find the problematic plugin(s).

    resetting the plugins folder by FTP or PhpMyAdmin. Sometimes, an apparently inactive plugin can still cause problems.

    Thread Starter Andrew Ledwith

    (@jaledwith)

    Unfortunately, after trying both your suggestions I’m still seeing the same problem.

    Out of curiosity, what happens if you place the number of posts right into the query rather than using the settings?

    ‘posts_per_page’ => 3

    I have seen other similar posts here and that seemed to work.

    Thread Starter Andrew Ledwith

    (@jaledwith)

    Thanks for replying, racer x.

    Unfortunately that did not fix the issue I’m having, but it is responding differently than before. No matter what I set posts_per_page to I’m able to load the first three pages of posts before returning a 404.

    Thread Starter Andrew Ledwith

    (@jaledwith)

    Okay, out of sheer frustration I decided to go about the problem an entirely different way. I scrapped everything I’d changed in home.php and used the default loop. Then, in my functionality plugin, I added the following:

    function my_get_posts( $query ) {
    	if ( is_home() && $query->is_main_query() )
    		$query->set( 'post_type', array( 'post', 'flnavs_podcast', 'flnavs_video', 'flnavs_resources' ) );
    	return $query;
    }
    add_filter( 'pre_get_posts', 'my_get_posts' );

    It achieves the desired results. Thanks to all who helped me try to figure this mess out.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Loop with multiple post types not rendering archive pages’ is closed to new replies.