Php 如何在WordPress中使用参数数组内的循环

Php 如何在WordPress中使用参数数组内的循环,php,arrays,wordpress,for-loop,Php,Arrays,Wordpress,For Loop,我想在搜索参数中使用一个循环,如下所示 $community = array("eleven_polls", "activities_coordinator", "attractively_priced_onsite_laundry_care_centers"); $community_count = count($community); $args = array( 'numberposts' => -1, 'post_type' => 'apartm

我想在搜索参数中使用一个循环,如下所示

$community = array("eleven_polls", "activities_coordinator", "attractively_priced_onsite_laundry_care_centers");
$community_count = count($community);

$args = array(
    'numberposts'   => -1,
    'post_type'     => 'apartment',
    'meta_query'    => array(
        'relation'      => 'AND',
        array(
            'relation' => 'AND',
            for ($i=0; $i < $community_count ; $i++) { 
                array(
                    'key'       => 'community',
                    'value'     => $_GET['community'][$i],
                    'compare'   => 'LIKE'
                ),
            }
        )
    )
);
$community=array(“十一次民意测验”、“活动协调人”、“价格诱人的现场洗衣护理中心”);
$community\u count=计数($community);
$args=数组(
“numberposts”=>-1,
“post_type”=>“公寓”,
“元查询”=>数组(
'关系'=>'和',
排列(
'关系'=>'和',
对于($i=0;$i<$community\u count;$i++){
排列(
“键”=>“社区”,
'value'=>$\u获取['community'][$i],
'比较'=>'类似'
),
}
)
)
);

但是它在for循环行上显示了语法错误,如何在数组中运行for循环

不要在数组中循环。像下面这样做

$community = array("eleven_polls", "activities_coordinator", "attractively_priced_onsite_laundry_care_centers");
$community_count = count($community);

$args = array(
    'numberposts'   => -1,
    'post_type'     => 'apartment',
    'meta_query'    => array(
    'relation'      => 'AND',
     array(
            'relation' => 'AND',

        )
    )
);


for ($i=0; $i < $community_count ; $i++) { 
               $args = array(
                    'key'       => 'community',
                    'value'     => $_GET['community'][$i],
                    'compare'   => 'LIKE'
                );
            }
$community=array(“十一次民意测验”、“活动协调人”、“价格诱人的现场洗衣护理中心”);
$community\u count=计数($community);
$args=数组(
“numberposts”=>-1,
“post_type”=>“公寓”,
“元查询”=>数组(
'关系'=>'和',
排列(
'关系'=>'和',
)
)
);
对于($i=0;$i<$community\u count;$i++){
$args=数组(
“键”=>“社区”,
'value'=>$\u获取['community'][$i],
'比较'=>'类似'
);
}
希望,它会像你所寻找的那样工作

echo '<pre>';
print_r($args);
echo '</pre>';

Array
(
    [numberposts] => -1
    [post_type] => apartment
    [meta_query] => Array
        (
            [relation] => AND
            [0] => Array
                (
                    [relation] => AND
                    [0] => Array
                        (
                            [key] => community
                            [value] => Array
                                (
                                    [0] => 0
                                )

                            [compare] => LIKE
                        )

                    [1] => Array
                        (
                            [key] => community
                            [value] => Array
                                (
                                    [0] => 1
                                )

                            [compare] => LIKE
                        )

                    [2] => Array
                        (
                            [key] => community
                            [value] => Array
                                (
                                    [0] => 2
                                )

                            [compare] => LIKE
                        )

                )

        )

)
echo';
打印费用($args);
回声';
排列
(
[numberposts]=>-1
[post_type]=>公寓
[元查询]=>数组
(
[关系]=>和
[0]=>阵列
(
[关系]=>和
[0]=>阵列
(
[key]=>社区
[值]=>数组
(
[0] => 0
)
[比较]=>喜欢吗
)
[1] =>阵列
(
[key]=>社区
[值]=>数组
(
[0] => 1
)
[比较]=>喜欢吗
)
[2] =>阵列
(
[key]=>社区
[值]=>数组
(
[0] => 2
)
[比较]=>喜欢吗
)
)
)
)
用于($i=0;$i<$community\u count;$i++){
$array=array(
“键”=>“社区”,
'value'=>$\u获取['community'][$i],
'比较'=>'类似'
),
}
$args=数组(
“numberposts”=>-1,
“post_type”=>“公寓”,
“元查询”=>数组(
'关系'=>'和',
排列(
'关系'=>'和',
$array
)
)
);

我不明白你想达到什么目的。但是试着这样做。

你不能在数组中执行循环,但是如何实现我想要的,你知道吗@developer先生请检查:您应该在数组关闭后删除逗号(,)。
for ($i=0; $i < $community_count ; $i++) { 
           $array =  array(
                    'key'       => 'community',
                    'value'     => $_GET['community'][$i],
                    'compare'   => 'LIKE'
                ),
            }


$args = array(
        'numberposts'   => -1,
        'post_type'     => 'apartment',
        'meta_query'    => array(
            'relation'      => 'AND',
            array(
                'relation' => 'AND',
                 $array

            )
        )
    );