Plugin Author
Ajay
(@ajay)
Hi, thank you for your kind words.
Take a look at this example on how to use the function and then use WP_Query to pull the post data. You’ll need to write the additional code to write some extra code to pull the post_meta etc. that you want.
https://gist.github.com/ajaydsouza/c8defd4b46e53240e376
If you’ve made changes and happy to share it, I’d like to add this as yet another example for users to see.
Thank you for your quick reply!
I could not understand:
if ($ topposts) {
// Implode the posts and set a varible to pass to our exclude stop.
$posts = implode (“,” $features);
}
What arguments, just i have to put in $features variable?
and how to sort the result by $orderby = “sumCount DESC” ?
I would like to make a more practical example?
It will be really cool if I can, is a nice example!
Plugin Author
Ajay
(@ajay)
Hi, I realised that that part of the code was wrong! I missed that variable 🙁
It should be:
if ( $topposts ) {
//Implode the posts and set a varible to pass to our exclude param.
$posts = implode( ",", $topposts );
}
$args = array(
'post__in' => $posts,
'posts_per_page' => 7,
'ignore_sticky_posts' => 1,
'orderby' => 'post__in',
);
Just i think implode is unnecessary ?…
Inserting the list of ids not in an array returns an error. ‘post__in’ => $posts,
$posts is a string. post__in accepts an array.
So instead of $posts could use ‘post__in’ => $ topposts skipping the $posts = implode (‘,’, $ topposts); all together …
For me it worked perfect that way!
And for those who need a specific custom_post set in array post_type => ‘my-post-custom’ …
Here’s how it was:
if ( function_exists( 'get_tptn_pop_posts' ) ) {
$topposts = get_tptn_pop_posts(); // Array of posts
$topposts = wp_list_pluck( $topposts, 'postnumber' );
$args = array(
'post__in' => $topposts,
'posts_per_page' => 5,
'ignore_sticky_posts' => 1,
'orderby' => 'post__in',
'post_type' => 'aps-products'
);
$my_query = new WP_Query( $args );
if ( $my_query->have_posts() ) {
while ( $my_query->have_posts() ) {
$my_query->the_post();
echo '<a href="' . get_permalink( get_the_ID() ) . '">';
the_title();
echo '</a>';
wp_reset_postdata();
}
} else {
}
wp_reset_query();
}
Then just customize to taste and pull the necessary post_meta!!
Once you have him on my personal site, I will leave here the link for those who want to be inspired …
One more question: How do I show the count?
Thanks for the support, I left a review 5 stars for this great plugin !!
What about time?
You can set?
One more question: How do I show the count?
Plugin Author
Ajay
(@ajay)
Hi, You’re right about the array. I’m still muddling up my various WP functions! I had originally imploded the array because I was using it with Ajax Load More which is another plugin that uses a shortcode that takes a comma separated list.
On the count, you could you use get_tptn_post_count_only( get_the_ID() ) to get the raw count for the post.
For the time, do you mean set the time of get the post time? For that you could use: https://codex.wordpress.org/Template_Tags/the_time
Or do you mean restricting the popular posts over a specific period?
For this you could pass a $arguments array to get_tptn_pop_posts with:
$arguments = array(
'daily' => TRUE,
'daily_range' => 10,
);