查询发布返回10条记录

时间:2013-01-07 作者:Lucky

我使用以下代码从自定义分类法中获取记录。

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\\u query->post\\u count返回10,即使实际记录数要多得多。我尝试过各种解决方案,但没有一种对我有效。这个问题可能是重复的,但我再次问这个问题,因为即使是一些答案对其他人也有用,但没有一个能给出很好的解释。谢谢

1 个回复
SO网友:luke

尝试取出\'paged\' => $paged 参数,因为它只是返回该页面的结果量,似乎设置为10。

(您需要执行两个单独的查询—一个用于获取真实计数,另一个用于以分页格式显示帖子。)

结束

相关推荐

Include taxonomy slug in url?

我有以下自定义帖子类型和自定义分类设置:add_action( \'init\', \'create_post_type\' ); function create_post_type() { register_post_type( \'system\', array( \'labels\' => array( \'name\' => __( \'Systems\' ),&#x

查询发布返回10条记录 - 小码农CODE - 行之有效找到问题解决它

查询发布返回10条记录

时间:2013-01-07 作者:Lucky

我使用以下代码从自定义分类法中获取记录。

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\\u query->post\\u count返回10,即使实际记录数要多得多。我尝试过各种解决方案,但没有一种对我有效。这个问题可能是重复的,但我再次问这个问题,因为即使是一些答案对其他人也有用,但没有一个能给出很好的解释。谢谢

1 个回复
SO网友:luke

尝试取出\'paged\' => $paged 参数,因为它只是返回该页面的结果量,似乎设置为10。

(您需要执行两个单独的查询—一个用于获取真实计数,另一个用于以分页格式显示帖子。)

相关推荐

Custom Taxonomy - fields

我有一个称为项目的自定义分类法,它有一个称为公寓的自定义post类型,两者都有acf自定义字段。我想将分类法创建的项目及其acf字段放在某个页面上,例如项目1、项目2。我创建了taxonomy-projects\\u公寓。php并将其用作模板,用于名为“项目”的页面。$args = array( \'taxonomy\' => \'projects\', \'orderby\' => $orderby, \'show_count