Pagination issue for Custom Post type in wordpress 3.0


#1

I need help please,

I am working on Custom post types ( wordpress 3.0 ) I am getting struck at displaying pagination for the posts.

bellow is my code:

<?php 
$loop = new WP_Query(array('post_type' => 'portfolio', 'orderby'=> 'menu_order', 'paged'=>$paged, 'posts_per_page' =>6)); 
	?>  

The “next” and “previous” links at the bottom should be displayed after 6 posts, but its not happening.

Any one might be got this problem and got solution.


#2

Try adding the following before your query:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

I’ve only tried it with a query_posts type query, so I’m not a 100% it will work with yours.


#3

Haven’t tried it in WP 3.0 yet, but try this: http://snipplr.com/view/32185/wordpress-paginated-wpquery/


#4
Try adding the following before your query:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

I’ve only tried it with a query_posts type query, so I’m not a 100% it will work with yours.

I tired it, it is not working.


#5
Haven't tried it in WP 3.0 yet, but try this: http://snipplr.com/view/32185/wordpress-paginated-wpquery/

This is too I tried but no luck.


#6

This is my portfolio page code, please help if any one have an idea what goes wrong.


<?php 
/* Template Name: Portfolio  page */
get_header(); ?>
<?php $loop = new WP_Query(array('post_type' => 'portfolio', 'orderby'=> 'menu_order', 'paged'=>$paged, 'posts_per_page' =>2)); ?> <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
  • <?php the_title(); ?>

    <?php the_post_thumbnail(); ?> <?php $img=get_post_meta($post->ID, 'Image', true); $timthumboption = get_option("timthumboption"); ?> <?php if($img) { ?> <?php if( $timthumboption == "0" ){?> <?php the_title(); ?> <?php } ?> <?php if( $timthumboption == "1" ){?> <?php the_title(); ?> <?php }?> <?php } else { ?> no image <?php } ?>

    <?php the_content_rss('', TRUE, '', 20); ?> view more
<?php endwhile; ?>
<?php next_posts_link('« Older Entries') ?>
<?php previous_posts_link('Newer Entries »') ?>
<?php get_footer(); ?>

#7

Try this mate, use caller_get_posts and reset the wp query after looping :slight_smile:

$args=array(
	'post_type' 		=> 'portfolio',
	'post_status'		=> 'publish',
	'orderby'                    => 'menu_order',
        'posts_per_page'         =>6
	'caller_get_posts'	        =>1,
	'paged'			=>$paged,
	);
query_posts($args);
while (have_posts()): the_post();

    //loop code here

endwhile;

//pagination code here

wp_reset_query();

hope this help,

good luck :slight_smile:


#8
Try this mate, use caller_get_posts and reset the wp query after looping :)
$args=array(
	'post_type' 		=> 'portfolio',
	'post_status'		=> 'publish',
	'orderby'                    => 'menu_order',
        'posts_per_page'         =>6
	'caller_get_posts'	        =>1,
	'paged'			=>$paged,
	);
query_posts($args);
while (have_posts()): the_post();

    //loop code here

endwhile;

//pagination code here

wp_reset_query();

hope this help,

good luck :slight_smile:

Thanks themesguy :slight_smile:


#9

the bellow code works for me:

<?php
        query_posts(array(
            'post_type' => 'portfolio', // can be custom post type
            'orderby'=> 'menu_order',
			'paged'=>$paged, 
			
        ));
        
        ?>

we can adjust the number of post to be displayed in wp admin dash board settings > reading.

Thanks friends for your help.


#10
the bellow code works for me:
<?php
        query_posts(array(
            'post_type' => 'portfolio', // can be custom post type
            'orderby'=> 'menu_order',
			'paged'=>$paged, 
			
        ));
        
        ?>

we can adjust the number of post to be displayed in wp admin dash board settings > reading.

Thanks friends for your help.

I’ve just stocked in same point. What if people want to show 6 posts on their portfolio page but 10 posts on blog page. With your solution they need to use same listing number for these two pages. In my case I’ve products, photos, portfolio(s) and blog and i want to let the user choose different listing numbers for the parts of theme. We have to find another solution mate :frowning:


#11

By the way, Kayapati’s first code (same with mine) is working if you give smaller value, e.g: 1, for “Blog pages show at most” on reading settings. But it’s not the case because user may want to use a “plugin” and the plugin can be using the number. I think it’s a bug! What do you think guys?


#12

Hi there,

I have almost the same problem as kayapati i hope somebody could help me. I found little diferent query for my custom post type but i’m newby in php and i don’t know how to aply the solution you guys post here to my case.

Here is my code:

<?php $recent = new WP_Query('post_type=pronun&posts_per_page=4'); while($recent->have_posts()) : $recent->the_post();?>


// some content
 

<?php endwhile; ?>

<?php previous_posts_link('‹ Previous Page') ?>
<?php next_posts_link('Next Page ›') ?>

That’s it. I’ll appreciate some help… thanks.


#13

Hi All,

I am having problem not on the custom post type template page. But on the single page of that custom post type i created single post page for my custom type but the next_post_link() and previous_post_link() not displaying anything.

Thanks
Neel


#14

-Hey guys a little help here please, I have the same issue with custom post types and the pagination (404 error) - http://pastie.org/1178764-

Ok my bad, 2 minutes after I posted this I resolved the issue with this post http://wordpress.org/support/topic/pagination-with-custom-post-type-getting-a-404?replies=1#post-1616810


#15

Hello!

There are several issues with custom post types and pagination. One of them can be solved by adding a post_type var to the url vars.

Example: example.com/category/books/page/2/?post_type=novels

Use this in your functions.php:

function custom_request($qv) {
if(isset($qs[‘category_name’])){
$qs[‘post_type’] = get_post_types($args = array(
‘public’ => true,
’_builtin’ => false
));
array_push($qs[‘post_type’],‘post’);
}
return $qs;
}
add_filter(‘request’, ‘custom_request’);

It also works for Author’s Archive, Feeds, and other places where you need the custom post types to appear.


#16
VagrantRadio said

Haven’t tried it in WP 3.0 yet, but try this: http://snipplr.com/view/32185/wordpress-paginated-wpquery/

This just saved me hours of pulling my hair out <3 thanks!


#17

Just remember adding the

'paged' => get_query_var( 'paged' );

to the query posts arguments array :slight_smile:


#18
matyo said
VagrantRadio said

Haven’t tried it in WP 3.0 yet, but try this: http://snipplr.com/view/32185/wordpress-paginated-wpquery/

This just saved me hours of pulling my hair out <3 thanks!

How did this help you @matyo?
How/Where do I throw in the post_type?