【问题标题】:Wordpress category & taxonomy loop with pagination带有分页的 Wordpress 类别和分类循环
【发布时间】:2015-11-27 20:07:30
【问题描述】:

我有两个属于同一帖子类型(帖子)的分类法。

冒险 - 属于类别分类
冒险——属于假日类型的分类法

我想运行两个查询:

$args = array(
            'post_type' => 'post',
            'tax_query' => array(
            'relation' => 'OR',
                array(
                    'taxonomy' => 'holiday-types',
                    'field'    => 'slug',
                    'terms'    => 'adventure',
                ),
                array(
                    'taxonomy' => 'category',
                    'field'    => 'slug',
                    'terms' => 'adventure',
                ),  
            ),

        );
        $the_query = new WP_Query( $args );

尽管术语相同,但它们关联的帖子却不同。

此查询仅返回带有假期类型分类的帖子,而不是类别分类。如果我用假期类型注释掉数组,那么分类类别会显示相关帖子。

我需要它们同时显示以及分页显示。

'paged' => get_query_var('paged')

我已经读到我需要将它添加到第一个数组中,但我想在我首先让循环正常工作之前我无法测试它。

请问我哪里出错了?

【问题讨论】:

  • 我现在有这个问题,但分页不起作用。当点击进入其他页面时,它会进入 404 页面,例如2、3、4。我错过了什么?

标签: php wordpress pagination taxonomy


【解决方案1】:

我现在有这个地方,但分页不起作用。当点击进入其他页面时,它会进入 404 页面,例如2, 3, 4. 我错过了什么?

global $query_string;
    $myquery = wp_parse_args($query_string);
    $myquery = array(
        'paged' => $paged,
        'numberposts'=>-1,
        'tax_query' => array(
            'relation' => 'OR',
            array(
                'taxonomy' => 'category',
                'terms' => array('adventure'),
                'field' => 'slug',

            ),
            array(
                'taxonomy' => 'holiday-types',
                'terms' => array('adventure'),
                'field' => 'slug',
            ),        
        ),
     );
    query_posts($myquery);

    while ( have_posts() ) : the_post();
        echo '<li>';
        the_title();
        echo '</li>';
    endwhile;

    // Reset Query
    wp_pagenavi();
    wp_reset_query();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-19
    • 2015-04-17
    • 2013-08-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    相关资源
    最近更新 更多