Last active
August 29, 2015 14:08
-
-
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.
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
// 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