Skip to content

Instantly share code, notes, and snippets.

@media317
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save media317/dc9d249e924521e597ee to your computer and use it in GitHub Desktop.
Save media317/dc9d249e924521e597ee to your computer and use it in GitHub Desktop.
Attempting to create a WordPress Loop that pulls the category slug from the custom field value of key cbc_category. The loop will pull all post with the category in the value of the custom field and display the featured image, title and excerpt.
// Add our custom loop
add_action( 'genesis_after_entry_content', 'media317_cat_loop' );
function media317_cat_loop() {
$cbccategory = genesis_get_custom_field('cbc_category');
$args = array(
'category_name' => $cbccategory,
'orderby' => 'post_date',
'order' => 'DESC',
'posts_per_page'=> '12', // overrides posts per page in theme settings
);
$loop = new WP_Query( $args );
if( $loop->have_posts() ) {
// loop through posts
while( $loop->have_posts() ): $loop->the_post(); ?>
<div class="one-third">
<a href="<?php the_permalink(); ?>"><img src="<?php get_the_post_thumbnail(); ?>"></a>
<h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p>
</div>
<?php
endwhile;
}
wp_reset_postdata();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment