Použití meta_query pro uživatelský typ příspěvků

WordPress 3.1 has made querying posts by postmeta values significantly simpler. With “meta_query” parameter, you can query for posts based on numerous postmeta values.

You have a custom post type called “product” that allows you to manage your T-shirt inventory. Upon saving each product, you enter custom field values for “price”, “size”, and “sex”. You want to create a page that only displays size “S” shirts for “men” that are under “$15.00″ and you want to order these posts by price, from lowest to highest.
In order to query for these products, you can use “meta_query”.


$args = array(
	'post_type' => 'product',
	'meta_query' => array(
		array(
			'key' => 'price',
			'value' => '15.00',
			'compare' => '<',
			'type' => 'NUMERIC'
		),
		array(
			'key' => 'size',
			'value' => 'S',
			'compare' => '=',
			'type' => 'CHAR'
		),
		array(
			'key' => 'sex',
			'value' => 'men',
			'compare' => '=',
			'type' => 'NUMERIC'
		)
	),
	'meta_key' => 'price',
	'orderby' => 'meta_value',
	'order' => 'ASC'
 );
$query = new WP_Query( $args );

Zdroj »