Last active
August 29, 2015 14:01
-
-
Save jprieton/2acacf46af651bbf94f8 to your computer and use it in GitHub Desktop.
Devolver los post mas vistos usando el plugin Wordpress Popular Posts
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
<?php | |
$post_type = 'post'; // post, page, custom_post_type | |
if (function_exists('wpp_get_mostpopular')) { | |
add_filter('wpp_html', 'wpp_get_array', 10, 2); | |
function wpp_get_array($content, $posts_data) { | |
$id = array(); | |
foreach ($posts_data as $item) { | |
$id[] = $item->id; | |
} | |
return $id; | |
} | |
$popular_posts_object = new WordPressPopularPosts; | |
$instance = array( | |
'range' => 'monthly', | |
'post_type' => $post_type | |
); | |
$popular_posts_ids = $popular_posts_object->get_popular_posts($instance); | |
} else { | |
$popular_posts_ids = array(); | |
} | |
$args = array( | |
'posts_per_page' => 6, | |
'post_type' => $post_type, | |
'post__in' => $popular_posts_ids | |
); | |
$popular_posts = get_posts($args); | |
foreach ($popular as $item) { | |
// Do something | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment