Query meta

Get posts by meta:

$args = array(
	'meta_key' => 'my_key',
	'meta_value' => 'my_value',
	'meta_compare' => '!=' 
	// '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'
);
query_posts( $args );

Get posts with ordering by meta:

$args = array(
	'orderby' => 'meta_value',
	'order' => 'DESC' // ASC
);
query_posts( $args );

Get posts by multiple meta:

query_posts( array(
	'post_type' => 'catalog',
	'meta_query' => array(
		array(
			'key' => 'price',
			'value' => array( 10, 20 ),
			'compare' => 'BETWEEN',
			'type' => 'numeric',
		),
		array(
			'key' => 'type',
			'value' => 'square',
			'compare' => 'NOT LIKE'
		)
	)
) );
VN:F [1.9.17_1161]
Rating: 0 (from 0 votes)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">