为什么这不会输出一些结果?

时间:2018-06-14 14:24:35

标签: php wordpress advanced-custom-fields

$args = array(
        'post_type'     => 'cp_test',
        'meta_query'    => array(
        'relation'      => 'OR',
            array(
                'key'       => 'team',
                'value'     => 'oud',
                'compare'   => '='
            ),
            array(
                'key'       => 'team',
                'value'     => 'jeugd',
                'compare'   => '='
            )
        )
    );

$the_query = new WP_Query( $args );
    if( $the_query->have_posts() ): 
        while ( $the_query->have_posts() ) : $the_query->the_post();
            $rows = get_field('wedstrijd');
            if($rows) : 
                foreach($rows as $row):
                    echo $row['stand'];
                endforeach;
            endif;
        endwhile; 
    endif; 

这不会返回任何输出为什么?如果没有meta_query,它将发布所有数据,但不会发布meta_query。请帮帮我!

2 个答案:

答案 0 :(得分:0)

args好像很好,但是你可以在https://www.billerickson.net/code/wp_query-arguments/检查参数的构造,看看你是否做得好。如果这是正确的,我会检查metakey是否写得正确,并尝试只使用一个meta_query来调试该错误。

答案 1 :(得分:-1)

如果您想要关键值的关系'是一个数组,ypou应该使用这个:

$args = array(
    'post_type'     => 'cp_test',
    'meta_query'    => array(
        'relation'      => array(
            'OR',
            array(
                'key'       => 'team',
                'value'     => 'oud',
                'compare'   => '='
                ),
           array(
               'key'       => 'team',
               'value'     => 'jeugd',
               'compare'   => '='
           ))
       )
);
相关问题