Skip to content

Instantly share code, notes, and snippets.

@JacobLett
Created August 7, 2015 18:01
Show Gist options
  • Save JacobLett/ddc3ddc798fd021cb2d6 to your computer and use it in GitHub Desktop.
Save JacobLett/ddc3ddc798fd021cb2d6 to your computer and use it in GitHub Desktop.
wordpress custom field loop
<?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