1

All

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 ?

<?php


                $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;">
                        <?php 

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

                        <table>

                            <th></th>
                            <tr>
                                <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>
                            </tr>
                            <tr>
                                <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>
                            </tr>
                            <tr>
                                <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>
                            </tr>
                        </table>
                    </div>

                    <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>
                    <div class="divider"></div>                 

                </div>

                <?php endwhile; ?>
                <?php 

            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
            ));?>
0
3

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

1
  • 1
    Thanks it works, edit please $global $paged; To global $paged; – Ajay Patel Jul 10 '12 at 5:34

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.