I have this query for custom filed values (array based values):
<?php
// args
$args = array(
'numberposts' => -1,
'post_type' => 'villa',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'amenities',
'value' => 'Internet',
'compare' => 'LIKE'
)
)
);
// get results
$the_query = new WP_Query( $args );
// The Loop
?>
<?php if( $the_query->have_posts() ): ?>
<ul>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<?php echo the_title(); ?>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
Now I want to generate bellow part dynamically:
array(
'key' => 'amenities',
'value' => 'Internet',
'compare' => 'LIKE'
)
)
Bellow is my implemented code but now working:
$amenities_exp = explode(",", $villa_amenities);
$aCount = 0;
$args = 'array(
\'numberposts\' => -1,
\'post_type\' => \'villa\',
\'meta_query\' => array(
\'relation\' => \'OR\',';
for($a=0; $a<count($amenities_exp); $a++){
"array(
'key' => 'amenities',
'value' => '".$amenities_exp[$a]."',
'compare' => 'LIKE'
)";
if($aCount != count($amenities_exp) - 1){
echo ",";
}else{
echo "";
}
$aCount++;
}
"));";