TeddyCoder | Web Freelancer in Hochiminh City

Filter by custom field

$wp_query = new WP_Query();
$param = array (
'posts_per_page' => '-1',
'post_type' => 'news',
'post_status' => 'publish',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'news_special',
'value' => 'special',
'compare' => '!='
))

);
$wp_query->query($param);
if($wp_query->have_posts()): while($wp_query->have_posts()) :$wp_query->the_post();

 

// Multi Custom field

 

$posts = get_posts(array(
	'numberposts'	=> -1,
	'post_type'		=> 'post',
	'meta_query'	=> array(
		'relation'		=> 'AND',
		array(
			'key'	 	=> 'color',
			'value'	  	=> array('red', 'orange'),
			'compare' 	=> 'IN',
		),
		array(
			'key'	  	=> 'featured',
			'value'	  	=> '1',
			'compare' 	=> '=',
		),
	),
));
BACK