分页不起作用wp_Query自定义字段值

时间:2012-07-09 作者:Ajay Patel

全部的

我希望那些帖子的post\\u type==profile,wpcf gender==1(男性)。

我试过这个密码

            $wp_query = new WP_Query( array( \'meta_key\' => \'wpcf-gender\', \'meta_value\' => \'1\', \'meta_compare\' => \'==\', \'post_type\' => \'profile\',\'posts_per_page\' => 2 ) );
我得到的结果很完美,但分页不起作用。你能帮我找到下面代码中的问题吗?

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

1 个回复
最合适的回答,由SO网友:Will 整理而成

您需要添加全局$paged,然后在传递给WP\\u Query的数组中,您需要添加“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 ) );
等等

结束

相关推荐

How to use pagination?

我有一个页面的以下代码,在这里我拉一张照片,标题和最后10篇文章的摘录。问题是,我不知道如何添加分页?我也安装了WP PageNavi。我已经看到一些类似的问题得到了解决,但我根本无法真正理解这个概念,我首先尝试确保这是可能的?<?php /* Template Name: Opinion */ ?> <?php get_header(); ?> <div id=\"primary\"> <div id=\"