0

I have an array that contains other arrays.

$args = array (
    'post_type' => 'clientes',
    'posts_per_page'    => -1,
    'orderby' => 'post_title',
    'order' => 'ASC',
    'meta_query' => array(
        array(
            'key'       => 'fecha_alta',
            'compare'   => '!=',
            'value'     => NULL,
            ),
        array(
            'relation' => 'OR',
            array(
                'key'       => 'fecha_baja',
                'compare'   => '>',
                'value'     => $trimestre['end'],
                ),
            array(
                'key'       => 'fecha_baja',
                'compare'   => '=',
                'value'     => NULL,
                ),
            ),
        ),
    );

I want to insert an array inside meta_query array based on a condition

if ($_GET['responsable']=='Pep' 

insert this array

array(
            'key'       => 'responsable',
            'compare'   => '=',
            'value'     => $responsable,
            ),

What is the best method to do this?

Thank you so much

2
  • Method "better" than what? Commented Apr 9, 2015 at 14:54
  • Sorry for my english jeje. I meant the best method. I change this on the question Commented Apr 9, 2015 at 14:56

1 Answer 1

1

just make like this:

$arr = [];

if(true){
$arr = [array data with true condition];
}else{
$arr = [array data with false condition];
}
....
$args = array (
    'post_type' => 'clientes',
    'posts_per_page'    => -1,
    'orderby' => 'post_title',
    'order' => 'ASC',
    'meta_query' => $arr[]
) 

or if you want to push data into meta array then you can use that according to your need

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.