• In my index.php, Im planning to query for my portfolio’s custom post type using wp_Query, everything works fine but the problems is when I try to add next_posts_link() to my loop.

    <li>In my wordpress backend setting->reading:
    I have set "Blog pages show at most = 1"</li>
    <li>In my template file:
    'posts_per_page' => 1</li>
    <li>There are total 8 posts in my post type.</li>
    <ul>

    When I include the codes in my index.php, the 1-3 page works fine but post beyond number 4 gives me error404…

    http://www.wthdesignbeta.net – works
    http://www.wthdesignbeta.net/?paged=2 – works
    http://www.wthdesignbeta.net/?paged=3 – works
    http://www.wthdesignbeta.net/?paged=4 – error
    http://www.wthdesignbeta.net/?paged=5 – error
    http://www.wthdesignbeta.net/?paged=6 – error
    http://www.wthdesignbeta.net/?paged=7 – error
    http://www.wthdesignbeta.net/?paged=8 – error

    <?php
    		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    		$loop = new WP_Query( array(
    			'post_type' => 'testv',
    			'posts_per_page' => 1,
    			'orderby'=> 'menu_order',
    			'paged'=>$paged
    		) );
    ?>  
    
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
    	<div class="accessory_image"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) { the_post_thumbnail(array(200,160)); } ?></a>
    			<?php the_title( '<h3 class="accessory-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h3>' ); ?>
    	</div>
    
    <?php endwhile; ?>
    
    <?php previous_posts_link('« Previous', $loop->max_num_pages); //for multiple post?>
    <?php next_posts_link('More »', $loop->max_num_pages); ?>

    I also print out the 2 arrays:

    <?php print_r($loop) ?>
    WP_Query Object ( [query_vars] => Array ( [post_type] => testv [tetts] => kksv [posts_per_page] => 1 [orderby] => menu_order [paged] => 1 [error] => [m] => 0 [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [name] => [static] => [pagename] => [page_id] => 0 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [tag] => [cat] => [tag_id] => [author_name] => [feed] => [tb] => [comments_popup] => [meta_key] => [meta_value] => [preview] => [s] => [sentence] => [fields] => [category__in] => Array ( ) [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( ) [tag_slug__and] => Array ( ) [ignore_sticky_posts] => [suppress_filters] => [cache_results] => 1 [update_post_term_cache] => 1 [update_post_meta_cache] => 1 [nopaging] => [comments_per_page] => 50 [no_found_rows] => [taxonomy] => tetts [term] => kksv [order] => DESC ) [tax_query] => WP_Tax_Query Object ( [queries] => Array ( [0] => Array ( [taxonomy] => tetts [terms] => Array ( [0] => kksv ) [include_children] => 1 [field] => slug [operator] => IN ) ) [relation] => AND ) [meta_query] => WP_Meta_Query Object ( [queries] => Array ( ) [relation] => ) [post_count] => 1 [current_post] => -1 [in_the_loop] => [comment_count] => 0 [current_comment] => -1 [found_posts] => 8 [max_num_pages] => 8 [max_num_comment_pages] => 0 [is_single] => [is_preview] => [is_page] => [is_archive] => 1 [is_date] => [is_year] => [is_month] => [is_day] => [is_time] => [is_author] => [is_category] => [is_tag] => [is_tax] => 1 [is_search] => [is_feed] => [is_comment_feed] => [is_trackback] => [is_home] => [is_404] => [is_comments_popup] => [is_paged] => [is_admin] => [is_attachment] => [is_singular] => [is_robots] => [is_posts_page] => [is_post_type_archive] => [query_vars_hash] => be7f2fd9150f0ef64058e987d630d1d4 [query_vars_changed] => [thumbnails_cached] => [query] => Array ( [post_type] => testv [tetts] => kksv [posts_per_page] => 1 [orderby] => menu_order [paged] => 1 ) [request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (38) ) AND wp_posts.post_type = 'testv' AND (wp_posts.post_status = 'publish') GROUP BY wp_posts.ID ORDER BY wp_posts.menu_order DESC LIMIT 0, 1 [posts] => Array ( [0] => stdClass Object ( [ID] => 78 [post_author] => 1 [post_date] => 2012-11-05 15:18:45 [post_date_gmt] => 2012-11-05 15:18:45 [post_content] => "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a [post_title] => 7. is lorem ipsum good? [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => 7-is-lorem-ipsum-good [to_ping] => [pinged] => [post_modified] => 2012-11-05 19:20:03 [post_modified_gmt] => 2012-11-05 19:20:03 [post_content_filtered] => [post_parent] => 0 [guid] => http://wthdesign.net/website/?post_type=testv&p=78 [menu_order] => 0 [post_type] => testv [post_mime_type] => [comment_count] => 0 [filter] => raw ) ) [post] => stdClass Object ( [ID] => 78 [post_author] => 1 [post_date] => 2012-11-05 15:18:45 [post_date_gmt] => 2012-11-05 15:18:45 [post_content] => "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a [post_title] => 7. is lorem ipsum good? [post_excerpt] => [post_status] => publish [comment_status] => closed [ping_status] => closed [post_password] => [post_name] => 7-is-lorem-ipsum-good [to_ping] => [pinged] => [post_modified] => 2012-11-05 19:20:03 [post_modified_gmt] => 2012-11-05 19:20:03 [post_content_filtered] => [post_parent] => 0 [guid] => http://wthdesign.net/website/?post_type=testv&p=78 [menu_order] => 0 [post_type] => testv [post_mime_type] => [comment_count] => 0 [filter] => raw ) )

    <?php print_r($wp_query) ?>

    WP_Query Object ( [query_vars] => Array ( [error] => [m] => 0 [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [name] => [static] => [pagename] => [page_id] => 0 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [tag] => [cat] => [tag_id] => [author_name] => [feed] => [tb] => [paged] => 0 [comments_popup] => [meta_key] => [meta_value] => [preview] => [s] => [sentence] => [fields] => [category__in] => Array ( ) [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( ) [tag_slug__and] => Array ( ) [ignore_sticky_posts] => [suppress_filters] => [cache_results] => 1 [update_post_term_cache] => 1 [update_post_meta_cache] => 1 [post_type] => [posts_per_page] => 1 [nopaging] => [comments_per_page] => 50 [no_found_rows] => [order] => DESC ) [tax_query] => WP_Tax_Query Object ( [queries] => Array ( ) [relation] => AND ) [meta_query] => WP_Meta_Query Object ( [queries] => Array ( ) [relation] => ) [post_count] => 1 [current_post] => -1 [in_the_loop] => [comment_count] => 0 [current_comment] => -1 [found_posts] => 3 [max_num_pages] => 3 [max_num_comment_pages] => 0 [is_single] => [is_preview] => [is_page] => [is_archive] => [is_date] => [is_year] => [is_month] => [is_day] => [is_time] => [is_author] => [is_category] => [is_tag] => [is_tax] => [is_search] => [is_feed] => [is_comment_feed] => [is_trackback] => [is_home] => 1 [is_404] => [is_comments_popup] => [is_paged] => [is_admin] => [is_attachment] => [is_singular] => [is_robots] => [is_posts_page] => [is_post_type_archive] => [query_vars_hash] => b52c7201ac0659efd0fc727f3f37d361 [query_vars_changed] => [thumbnails_cached] => [query] => Array ( ) [request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.post_date DESC LIMIT 0, 1 [posts] => Array ( [0] => stdClass Object ( [ID] => 6 [post_author] => 1 [post_date] => 2012-10-23 09:11:41 [post_date_gmt] => 2012-10-23 09:11:41 [post_content] =>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or- less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
    
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the t
    [post_title] => gdfgdfgdf [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => open [post_password] => [post_name] => gdfgdfgdf [to_ping] => [pinged] => [post_modified] => 2012-11-05 10:23:24 [post_modified_gmt] => 2012-11-05 10:23:24 [post_content_filtered] => [post_parent] => 0 [guid] => http://wthdesign.net/website/?p=6 [menu_order] => 0 [post_type] => post [post_mime_type] => [comment_count] => 1 [filter] => raw ) ) [post] => stdClass Object ( [ID] => 6 [post_author] => 1 [post_date] => 2012-10-23 09:11:41 [post_date_gmt] => 2012-10-23 09:11:41 [post_content] =>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or- less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
    
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the t
    [post_title] => gdfgdfgdf [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => open [post_password] => [post_name] => gdfgdfgdf [to_ping] => [pinged] => [post_modified] => 2012-11-05 10:23:24 [post_modified_gmt] => 2012-11-05 10:23:24 [post_content_filtered] => [post_parent] => 0 [guid] => http://wthdesign.net/website/?p=6 [menu_order] => 0 [post_type] => post [post_mime_type] => [comment_count] => 1 [filter] => raw ) )

    I suspect there is something wrong with the max_num_pages, because it is showing 3 for $wp_query but 8 for $loop……

Viewing 1 replies (of 1 total)
  • I believe that the problem is that previous/next_posts_link() works with query_posts(), not WP_Query().

    Try replacing the WP_Query with query_posts().

Viewing 1 replies (of 1 total)
  • The topic ‘Error 404 when using custom wp_query pagination’ is closed to new replies.