WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


I want those post having post_type == profile And wpcf-gender == 1 (male).

I tried this code

            $wp_query = new WP_Query( array( 'meta_key' => 'wpcf-gender', 'meta_value' => '1', 'meta_compare' => '==', 'post_type' => 'profile','posts_per_page' => 2 ) );

Results which I am getting is perfect but pagination is not working. Can you please help me to find what is the issue in below code ?


                $temp = $wp_query;
                $wp_query = null;

                $wp_query = new WP_Query( array( 'meta_key' => 'wpcf-gender', 'meta_value' => '1', 'meta_compare' => '==', 'post_type' => 'profile','posts_per_page' => 2 ) );
                <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

                <div class="post" id="post-<?php the_ID(); ?>">                 
                <h2 class="page-title"><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h2>
                    <div class="page-image">
                        <div class="page-image-overlay-child"></div>
                        <span style="float: left;padding-right: 50px;">

                            if(has_post_thumbnail()) {
                            } else {
                                 echo '<img src="'.get_bloginfo("template_url").'/images/header-image-1.jpg" alt="" />';


                                <td style="padding: 10px;"><strong>First Name:</strong> <?php echo do_shortcode('[types field="first-name" class="" style=""]'); ?></td>
                                <td style="padding: 10px;"><strong>Last Name:</strong> <?php echo do_shortcode('[types field="last-name" class="" style=""]'); ?></td>
                                <td style="padding: 10px;"><strong>Gender:</strong> <?php echo do_shortcode('[types field="gender"][/types]'); ?></td>
                                <td style="padding: 10px;"><strong>DOB:</strong> <?php echo do_shortcode('[types field="dob" style="text" format="F j, Y"][/types]'); ?></td>
                                <td style="padding: 10px;"><strong>City:</strong> <?php echo do_shortcode('[types field="city"]'); ?></td>
                                <td style="padding: 10px;"><strong>State:</strong> <?php echo do_shortcode('[types field="state"]'); ?></td>

                    <div class="divider"></div>
                    <div class="entry">
                        <?php the_excerpt(); ?> 
                        <input type="button" value="Read more..." id="searchsubmit" class="readmore" onClick="javascript:location.href = '<?php the_permalink();?>';" >
                    <div class="divider"></div>                 


                <?php endwhile; ?>

            global $wp_query;

            $big = 999999999; // need an unlikely integer

            echo paginate_links( array(
                'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                'format' => '?paged=%#%',
                'current' => max( 1, get_query_var('paged') ),
                'total' => $wp_query->max_num_pages
share|improve this question
up vote 3 down vote accepted

you need to add global $paged and then in your array that is being passed to WP_Query you need to add 'paged' => $paged

global $paged;
$temp = $wp_query;
                    $wp_query = null;

                    $wp_query = new WP_Query( array( 'meta_key' => 'wpcf-gender', 'meta_value' => '1', 'meta_compare' => '==', 'post_type' => 'profile','posts_per_page' => 2, 'paged' => $paged ) );

and so forth

share|improve this answer
Thanks it works, edit please $global $paged; To global $paged; – Ajay Patel Jul 10 '12 at 5:34
thanks for pointing that out. glad you got it sorted. – Will the Web Mechanic Jul 10 '12 at 12:36

Your Answer


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.