• Resolved meltz

    (@meltz)


    How can I loop through to create more meta query for ‘key’ => ‘epd_research’ based on the checkbox checked by user ? The code below show what I want to do but is obviously wrong.

    Thanks

    $args = array (
    		'cat' => $catID,
    		'posts_per_page' => -1,
    		'orderby' => 'title',
    		'order' => 'ASC',
    		'meta_query' => array(
    			'relation' => 'AND',
    			array(
    				'key' => 'position',
    				'value' => $position,
    				'compare' => '='
    			),
    
    			foreach($researchArray as $value) :
    
    				array(
    					'key' => 'epd_research',
    					'value' => '"$value"',
    					'compare' => 'LIKE'
    				)
    
    			endforeach;
        		)
    	);
Viewing 2 replies - 1 through 2 (of 2 total)
  • I think this will do what you want:

    $args = array (
          'cat' => $catID,
          'posts_per_page' => -1,
          'orderby' => 'title',
          'order' => 'ASC',
          'meta_query' => array(
             'relation' => 'AND',
             array(
                'key' => 'position',
                'value' => $position,
                'compare' => '='
             ),
          )
     );
    
    foreach($researchArray as $value) :
    
       $args['meta_query'][] =array(
          'key' => 'epd_research',
          'value' => "'$value'",
          'compare' => 'LIKE'
       );
    
    endforeach;
    Thread Starter meltz

    (@meltz)

    Thanks for the help =)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Multiple meta query based on acf checkbox checked’ is closed to new replies.