I've spent hours trying to figure this out, tried TONS of different methods and all failed in their own way.

What I'm trying to do:

Limit home page custom post types (woo_estate) to 6 and then paginate the rest.

What happens:

Not only the home page custom post types don't get limited, no pagination is added.

Current template code that loads in home page:



Yeah, I did something like this recently, but this is how I did it:

 $showNum = 10;
 $startNum = 0;

 if($paged > 0){
    $pageNum = $paged - 1;
    $startNum = $pageNum * $showNum;
 } elseif($paged == 0){
    $paged = 1;

Then I went ahead and used the modified $paged value to request entries within the range of the requested page.

In the code sample you provided, you are defining $paged on line two. If this is a template file, then the $paged variable should already be defined by the time it gets to this page.

If I'm understanding it right, the $paged variable is used for determining what page of the set you are on. Do a var_dump($wp_query); to figure out what the current value of $paged is on your system.

Maybe this will help.

| improve this answer | |
  • It's the home page, I have no idea how to define it by the time it gets to this page as most users just navigate directly to this page by entering the website address. Furthermore, I replaced my own $paged variable at top with the one you gave and I didn't see any changes. Surely I'm doing something wrong but my newbie knowledge limits my understanding of where and how. – Claudio Delgado Sep 7 '12 at 11:35
  • this is the website address by the way: daycagayrimenkul.com – Claudio Delgado Sep 7 '12 at 11:36
  • var_dump($wp_query); contents: codepad.viper-7.com/H4heWm – Claudio Delgado Sep 7 '12 at 11:39
  • Are you passing posts_per_page = -1 to the function? – Rutwick Gangurde Sep 10 '12 at 11:29

As you are using a custom WP_Query and WP_PageNavi, this is what will solve the pagination issue:

        'query' =>$my_query

Check it an confirm if this works!

| improve this answer | |
  • Did that but nothing changed, the page still shows all the posts although I want 6 to be shown but there's no errors either. No navigation still. See it in action: daycagayrimenkul.com – Claudio Delgado Sep 7 '12 at 11:33

I had a double query and that was why nothing worked.


helped me find out about this fact.

A lot of the codes I used should have worked in the first place.

Once the double query was removed, everything worked again.

| improve this answer | |
  • Cool, at least something I suggested worked. :) – Brent Sep 7 '12 at 20:10

Hi Ano paste this code in your function.php and this might help you

function change_custom_posts_per_page($query)
    if( !empty( $query->query_vars['post_type'] ) ) {
        switch ( $query->query_vars['post_type'] )
            case 'woo_estate':  // Post Type name
                $query->query_vars['posts_per_page'] = 6;

    return $query;

if( !is_admin() )
    add_filter( 'pre_get_posts', 'change_custom_posts_per_page' );
| improve this answer | |
  • Thanks for the answer but I already fixed the issue, turns out I had a double query coming from the parent template file and removing it solved everything. – Claudio Delgado Sep 8 '12 at 0:06

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.