Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using the following code to fetch records from a custom taxonomy.

if ($_GET['post_type'] == "developments"){ ?>
                    <?php 
                    global $wp_query;
                    $paged = $wp_query->query_vars['paged'];

                    $development_args = array(
                        'post_type' => $_GET['post_type'],
                        'orderby' =>'title',
                        'order' => 'ASC',
                        'posts_per_page' => 14,
                        'paged' => $paged, 
                        's' => $_GET['search_building_name'],
                    );
                    $development_args['meta_query'] = array(
                        'relation'=>'AND',
                        array(
                            'key' => 'total_units',
                            'type' => 'numeric',
                            'value' => $_GET['search_total_units'],
                            'compare' => $_GET['total_units_operator']
                        ),
                        array(
                            'key' => 'total_floors',
                            'type' => 'numeric',
                            'value' => $_GET['search_total_floors'],
                            'compare' => $_GET['total_floors_operator']
                        ),
                    );
                    $development_args['tax_query'] = array(
                        'relation' => 'AND',
                        array(
                            'taxonomy' => 'type',
                            'field' => 'slug',
                            'terms' => $_GET['search_type'],
                            //'operator' => 'AND'
                        ),
                        array(
                            'taxonomy' => 'amenities',
                            'field' => 'slug',
                            'terms' => $_GET['search_amenities'],
                            'operator' => 'AND'
                        ),
                        array(
                            'taxonomy' => 'style',
                            'field' => 'slug',
                            'terms' => $_GET['search_style'],
                            'operator' => 'AND'
                        ),
                    );
                    if ($_GET['search_neighborhood'] != 'any'){
                    $development_args['tax_query'][] = array(
                            'taxonomy' => 'neighborhood',
                            'field' => 'slug',
                            'terms' => $_GET['search_neighborhood'],
                        );
                    }
                    if ($_GET['search_developer'] != 'any'){
                    $development_args['tax_query'][] = array(
                            'taxonomy' => 'developer',
                            'field' => 'slug',
                            'terms' => $_GET['search_developer'],
                        );
                    }                       
                    if ($_GET['search_architect'] != 'any'){
                    $development_args['tax_query'][] = array(
                            'taxonomy' => 'architect',
                            'field' => 'slug',
                            'terms' => $_GET['search_architect'],
                        );
                    }                       
                    if ($_GET['search_delivered'] != 'any'){
                    $development_args['tax_query'][] = array(
                            'taxonomy' => 'delivered',
                            'field' => 'slug',
                            'terms' => $_GET['search_delivered'],
                        );
                    }                       

                    query_posts($development_args );
                }

$wp_query->post_count returns 10, even when the actual number of records is lot more. I have tried various solutions but none work for me. This question could be a duplicate but i am asking this again because even a few answers have worked for other people but none have given a good explanation. Thanks

share|improve this question
1  
That is a lot of conditions. Are you sure there are more than 10? Tip: Don't use query_posts use a new WP_Object instead and var_dump the object afterwards. You can see the actual SQL. Maybe that will give you a clue as to the problem. –  s_ha_dum Jan 7 '13 at 23:09
    
yes i am sure that it has more than 10 –  Lucky Jan 7 '13 at 23:24
    
Then try the debugging suggestion. It may help you spot why the query is returning the wrong count. –  s_ha_dum Jan 8 '13 at 4:57
add comment

1 Answer

Try taking out the 'paged' => $paged parameter, as it is simply returning the amount of results for that page, which seems to be set at 10.

(You will need to do two separate queries - one for getting the true count, and one for displaying the posts in a paginated format.)

share|improve this answer
1  
You don't need two queries, $wp_query->found_posts will give you the total number of posts for the query, regardless of pagination parameters. It looks like posts_per_page is set to 14 though, according to the query vars, so it would seem to not be related to pagination. –  Milo Jan 8 '13 at 3:08
    
$wp_query->found_posts is much better! didn't know about this –  luke Jan 8 '13 at 3:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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