WordPress: WP Query with Custom Fields

$args = 
	array(
		'posts_per_page' => -1,
		'meta_key' => 'city',
		'orderby' => 'meta_value',
		'order' => 'ASC',

		'meta_query' => array(
			array(
					'key' => 'destination_type',
					'value' => 'city, state',
					'compare' => 'IN'
				),
			
			array(
					'key' => 'country',
					'value' => $country,
					'compare' => '='
				),
			
			array(
					'key' => 'best_time',
					'value' => $month,
					'compare' => 'LIKE'
				),
			
			array(
					'key' => 'type',
					'value' => $type,
					'compare' => 'LIKE'
				)
			)
		);

		$the_query = new WP_Query( $args );

		if ( $the_query -> have_posts() ) :
		echo '
'; while ( $the_query->have_posts() ) : $the_query->the_post(); echo ''; endwhile; echo '
endif; wp_reset_query(); wp_reset_postdata();

Popularity: 18% [?]

This entry was posted in Wordpress. Bookmark the permalink.

Leave a Reply

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