Question

Is there a difference between the following codes? What exactly is the difference?

$args = array(
 'post_type' => $post_type,
 'numberposts'  => -1,          
 'post_status'  => 'publish',
 'meta_query' => array(

        array(
            'key' => $meta_key,
            'value' => $meta_value,
            'compare' => 'LIKE'         
        ),
    )
);

Compared with:

$args = array(
            'post_type' => $post_type,
            'numberposts'   => -1,          
            'post_status'   => 'publish',
        );

$args['meta_query'][] = array(
                'key' => $meta_key,
                'value' => $meta_value, 
                'compare' => 'LIKE');
        }

Thanks!

Was it helpful?

Solution

There's no difference in the two code snippets.

$args will be identical in both cases.

OTHER TIPS

To get the difference between 2 arrays you can use array_diff like this:

var_dump(array_diff($args, $args2));

This will print out the difference between the 2 arrays as an array. In your case an empty array as there are no differences.

Try to take a look at this: http://codepad.org/nZ2c5ksP

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top