2

I have a problem when using Wordpress 3.4. My "Products" custom post type pagination doesn't work. Here is the code I use

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$loop = new WP_Query( array(
'post_type' => 'products',
'posts_per_page' => PER_PAGE_DEFAULT,
'paged'=>$paged
) );

That code works well in previous WP version (Wordpress 3.3.2) but not in current version i.e. 3.4. What am I doing wrong?

7
  • 1
    What is this PER_PAGE_DEFAULT? Try replacing it with a static value for testing, say 3 and then see if the pagination works. – Rutwick Gangurde Jun 23 '12 at 5:10
  • It looks like the global problem. Here the some kind of sulution — wordpress.org/support/topic/… . – MaximOrlovsky Jun 23 '12 at 6:08
  • Rutwick Gangurde : PER_PAGE_DEFAULT is a number of posts that equals to 'Blog pages show at most' value in Reading Settings. I replaced it with 'posts_per_page' => 3, But it doesn't work also. – Kharis Blank Jun 23 '12 at 7:51
  • Maxim Orlovsky : Thank you for the link. I found the sollution. I replaced class-wp.php file in wp-includes directory with the class-wp.php of 3.3.2 version. The result, pagination works well. In right footer of WP admin still says Version 3.4. It doesn't change the version. How do you think about this? Is it allowable or not? Thank you for your responds. – Kharis Blank Jun 23 '12 at 7:54
  • @KharisBlank this will break as soon as you update to a new version. Changing core files is a bad idea. Use the pre_get_posts hook shown in the wordpress.org thread linked above. – Evan Jun 23 '12 at 8:13
1

Use get_query_var('page') instead of get_query_var('paged'). Related ticket: #21028

1
  • Molnarm: Thank you for you. I added this in functions.php: if ( ! function_exists( 'ucc_add_cpts_to_pre_get_posts' ) ) { function ucc_add_cpts_to_pre_get_posts( $query ) { if ( $query->is_main_query() && ! is_post_type_archive() && ! is_archive() && ! is_search() && ! is_singular() && ! is_404() ) { $my_post_type = get_query_var( 'post_type' ); if ( empty( $my_post_type ) ) { $query->set('post_type', 'products'); } } } } add_action( 'pre_get_posts', 'ucc_add_cpts_to_pre_get_posts' ); It works without get_query_var – Kharis Blank Jun 29 '12 at 23:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.