wp查询数组中的while循环 [英] while loop in wp query array

查看:48
本文介绍了wp查询数组中的while循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个wordpress数组,并且需要为每个'AND'关系建立一个while循环:

I got this wordpress array and need a while loop inside for every 'AND' relation:

$query_args = array(
'post_type' => 'post',
'post_status' => 'publish',
'meta_query' => array(
    'relation' => 'OR',
    array(
        'relation' => 'AND',
        array(
            'key'       => 'foo_0_start',
            'compare'   => '>=',
            'value'     => '$start'
        ),
        array(
            'key'       => 'foo_0_end',
            'compare'   => '<=',
            'value'     => '$end'
        )
    ),
    array(
        'relation' => 'AND',
        array(
            'key'       => 'foo_1_start',
            'compare'   => '>=',
            'value'     => '$start'
        ),
        array(
            'key'       => 'foo_1_end',
            'compare'   => '<=',
            'value'     => '$end'
        )
    )
)
);

我一直在寻找时间,并试图构建一个没有成功的函数。我该如何解决这个问题?

I was searching for hours and tried to build a function without success. How can I accomplish this issue? And what happens with the "'relation' => 'OR',"?

$query_args = array(
'post_type' => 'post',
'post_status' => 'publish',
'meta_query' => array()
);

$i = 1;
while ($i<=5;) :
$i++
$query_args['meta_query'][] = array (
    'relation' => 'AND',
    array(
        'key'       => 'foo_$i_start',
        'compare'   => '>=',
        'value'     => '$start'
    ),
    array(
        'key'       => 'foo_$i_end',
        'compare'   => '<=',
        'value'     => '$end'
    )
);
endwhile;

我们将不胜感激。

推荐答案

确定。找到了解决方案:

ok. Found the solution:

$query_args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'meta_query' => array('relation' => 'OR')
);

$i = 1;
while ($i<=5) :
    $i++;
    $query_args['meta_query'][] = array (
        'relation' => 'AND',
        array(
            'key'       => 'foo_' . $i . '_start',
            'compare'   => '>=',
            'value'     => '$start'
        ),
        array(
            'key'       => 'foo_' . $i . '_end',
            'compare'   => '<=',
            'value'     => '$end'
        )
    );
endwhile;

这篇关于wp查询数组中的while循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆