Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active July 17, 2018 15:10
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 billerickson/2f3e532474f8a57f3a4968d2d2947817 to your computer and use it in GitHub Desktop.
Save billerickson/2f3e532474f8a57f3a4968d2d2947817 to your computer and use it in GitHub Desktop.
<?php
/**
* Featured Posts
* Display 5 posts from the "featured posts" category, published in the
* last 2 weeks, sorted by share count.
*/
function ea_featured_posts() {
$loop = get_transient( 'ea_featured_posts' );
if( false === $loop ) {
$loop = new WP_Query( array(
'posts_per_page' => 5,
'category_name' => 'featured-posts',
'orderby' => 'meta_value_num',
'meta_key' => 'shared_counts_total',
'order' => 'DESC',
'date_query' => array( array( 'after' => '2 weeks ago' ) )
) );
set_transient( 'ea_featured_posts', $loop, DAY_IN_SECONDS );
}
// ...
}
add_action( 'genesis_before_loop', 'ea_featured_posts' );
// Build the page
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment