Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

WP query filtered by custom fields

Retrieve only “Products”, under 500 USD, with blue OR red color.

// WP_Query arguments
$args = array(
	'post_type'              => array( 'product' ),
	'order'                  => 'ASC',
	'orderby'                => 'title',
	'meta_query'             => array(
		'relation' => 'AND',
		array(
			'key'     => 'price',
			'value'   => '500',
			'compare' => '<',
			'type'    => 'NUMERIC',
		),
		array(
			'relation' => 'OR',
			array(
				'key'     => 'color',
				'value'   => 'blue',
				'compare' => '=',
			),
			array(
				'key'     => 'color',
				'value'   => 'red',
				'compare' => '=',
			),
		),
	),
);

// The Query
$query = new WP_Query( $args );