-1

尝试使用array_push将下面的数组添加到现有数组中:

'tax_query' => array(
        'relation' => 'and',
        array(
            'taxonomy' => 'type',
            'field' => 'slug',
            'terms' => 'national'
            )
    )

现有数组:

$args = array(
        'post_type' => 'events',       
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key' => 'events_start-date',
                'value' => date('YYYY-mm-dd'),
                'type' => 'CHAR',
                'compare' => '>='
            )
        )
);

我试过这段代码没有运气:

array_push(
$args, array('tax_query'=> array('relation' => 'and', 
array('taxonomy' => 'prince-range','field' => 'slug','terms' => '99')
)));
4

3 回答 3

1

你把事情复杂化了。

$args['tax_query'] = array(
     'relation' => 'and',
          array(
               'taxonomy' => 'type',
               'field' => 'slug',
               'terms' => 'national'
         )
     );
于 2013-05-29T01:52:59.610 回答
0
$merged = array_merge($args, $array_to_merge);

一旦您合并 2 个数组 - 您需要使用array_merge,而不是array_push

在线演示:http: //ideone.com/jHQipV

于 2013-05-29T01:57:33.333 回答
0
$arr = array('tax_query' => array(
        'relation' => 'and',
        array(
            'taxonomy' => 'type',
            'field' => 'slug',
            'terms' => 'national'
            )
    )
);

$args = array(
        'post_type' => 'events',       
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key' => 'events_start-date',
                'value' => date('YYYY-mm-dd'),
                'type' => 'CHAR',
                'compare' => '>='
            )
        )
);

$args[] = $arr;

var_dump 上$args

array(3) { ["post_type"]=> string(6) "events" ["meta_query"]=> array(2) { ["relation"]=> string(3) "AND" [0]=> array(4) { ["key"]=> string(17) "events_start-date" ["value"]=> string(26) "2013201320132013-0505-2929" ["type"]=> string(4) "CHAR" ["compare"]=> string(2) ">=" } } [0]=> array(1) { ["tax_query"]=> array(1) { ["relation"]=> array(3) { ["taxonomy"]=> string(4) "type" ["field"]=> string(4) "slug" ["terms"]=> string(8) "national" } } } } 
于 2013-05-29T02:00:36.950 回答