Created
August 7, 2015 18:01
-
-
Save JacobLett/ddc3ddc798fd021cb2d6 to your computer and use it in GitHub Desktop.
wordpress custom field loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Look for cookie set by country select dropdwon | |
if(isset($_COOKIE['altairUniCountry'])){ | |
$showCntryID = $_COOKIE["altairUniCountry"]; | |
//Make the class lowercase | |
$showCntryClass = strtolower($showCntryID); | |
} | |
else{ | |
// Cookie is not set use these default values | |
$showCntryID = 'GLOBAL'; | |
$showCntryClass = 'global'; | |
} | |
// query args | |
$args = array( | |
'post_type' => 'post', | |
'posts_per_page' => 10, | |
'post_status' => 'publish', | |
'meta_query' => array( | |
array( | |
'key' => 'country', | |
'value' => 'show-'. $showCntryClass, | |
'compare' => '=' | |
) | |
) | |
); | |
$country_query = new WP_Query( $args ); | |
while($country_query->have_posts()) : $country_query->the_post(); | |
?> | |
<?php if( $the_query->have_posts() ): ?> | |
<ul> | |
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?> | |
<li> | |
<a href="<?php the_permalink(); ?>"> | |
<?php the_title(); ?> | |
<?php the_meta(); ?> | |
</a> | |
</li> | |
<?php endwhile; ?> | |
</ul> | |
<?php endif; ?> | |
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment