Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WordPress术语循环,foreach和WP_Qurey作为嵌套循环问题_Wordpress - Fatal编程技术网

WordPress术语循环,foreach和WP_Qurey作为嵌套循环问题

WordPress术语循环,foreach和WP_Qurey作为嵌套循环问题,wordpress,Wordpress,我已经为常见问题和自定义分类创建了自定义帖子类型,以组织问题和答案 此外,我还创建了一个单页模板,使用下面的代码来显示常见问题解答 $terms = get_terms( 'faq_categories', array( 'orderby' => 'name', 'order' => 'ASC' ) ); foreach($terms as $term) { ?> <h3>&l

我已经为常见问题和自定义分类创建了自定义帖子类型,以组织问题和答案

此外,我还创建了一个单页模板,使用下面的代码来显示常见问题解答

$terms = get_terms(
    'faq_categories',
    array(
        'orderby'   =>  'name',
        'order'     =>  'ASC'
    )
);

foreach($terms as $term)
{
    ?>
    <h3><?php echo $term->name; ?></h3>
    <?php

    $q_args = array(
        'post_type'         =>  'faq',
        'tax_query'         =>  array(
            'taxonomy'  =>  'faq_categories',
            'field'     =>  'slug',
            'terms'     =>  $term->slug
        ),
        'posts_per_page'    =>  -1
    );

    wp_reset_postdata();
    wp_reset_query();

    $ans    =   new WP_Query($q_args);

    while($ans->have_posts())
    {
        $ans->the_post();

        ?>
        <h5><?php echo the_title(); ?></h5>
        <?php
    }
}
此外,在wp\U查询循环之前和之后,我尝试了wp\U reset\u postdate()wp\U reset\u query(),我也尝试过删除它们,但运气不佳

有没有办法解决这个问题

问候
Merianos Nikos

tax_查询接受数组数组

$q_args = array(
    'post_type'         =>  'faq',
    'tax_query'         =>  array(
        array(
            'taxonomy'  =>  'faq_categories',
            'field'     =>  'slug',
            'terms'     =>  $term->slug
        )
    ),
    'posts_per_page'    =>  -1
);
或者重写查询,您实际上不需要税务查询:

$ans = new WP_Query("post_type=faq&faq_categories=$term->slug&posts_per_page=-1");
$ans = new WP_Query("post_type=faq&faq_categories=$term->slug&posts_per_page=-1");