Skip to content

Instantly share code, notes, and snippets.

@kylephillips
Last active July 27, 2020 03:11
Show Gist options
  • Save kylephillips/0b94c9151f58b598866c to your computer and use it in GitHub Desktop.
Save kylephillips/0b94c9151f58b598866c to your computer and use it in GitHub Desktop.
Favorites for WordPress - Display the most favorited posts
<?php
/**
* Display a list of the 10 most favorited posts
* @see https://wordpress.org/plugins/favorites/
*/
$favorites_query = new WP_Query(array(
'post_type' => array('post'),
'posts_per_page' => 10,
'meta_key' => 'simplefavorites_count',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'ignore_sticky_posts' => true
));
if ( $favorites_query->have_posts() ) :
echo '<h3>' . __('Top Favorited Posts', 'textdomain') . '</h3><ul>';
while ( $favorites_query->have_posts() ) : $favorites_query->the_post();
echo '<li>' . get_the_title() . ': ' . get_post_meta(get_the_id(), 'simplefavorites_count', true) . '</li>';
endwhile;
echo '</ul>';
endif; wp_reset_postdata();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment