Search code examples
phparraysmultidimensional-arrayarray-push

Array Push a Multi Dimentional Array


trying to add the array below into an existing one with array_push:

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

the existing array:

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

i have tried this code with no luck:

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

Solution

  • You’re over complicating it.

    $args['tax_query'] = array(
         'relation' => 'and',
              array(
                   'taxonomy' => 'type',
                   'field' => 'slug',
                   'terms' => 'national'
             )
         );