admin管理员组文章数量:1130349
I want to show custom posts views counter. Also, I want to create a shortcode so that I can show it anywhere. Currently, It shows the custom posts list but with the "0" view. Can it be increased?
Here is the code so far:
function getPostViews($postID){
$author_id = '';
$author_posts = get_posts( array(
'author' => $author_id,
'post_type' => 'video'
) );
$counter = 0;
foreach ( $author_posts as $post )
{
$views = absint( get_post_meta( $post->ID, 'views', true ) );
$counter += $views;
echo "<li style='color:#000;'>{$post->post_title} ({$views})</li>";
}
echo "</ul><hr /><p style='color:#000;'>Total Number of views: <strong>
{$counter}</strong></p>";
}
add_shortcode('view','getPostViews');
I want to show custom posts views counter. Also, I want to create a shortcode so that I can show it anywhere. Currently, It shows the custom posts list but with the "0" view. Can it be increased?
Here is the code so far:
function getPostViews($postID){
$author_id = '';
$author_posts = get_posts( array(
'author' => $author_id,
'post_type' => 'video'
) );
$counter = 0;
foreach ( $author_posts as $post )
{
$views = absint( get_post_meta( $post->ID, 'views', true ) );
$counter += $views;
echo "<li style='color:#000;'>{$post->post_title} ({$views})</li>";
}
echo "</ul><hr /><p style='color:#000;'>Total Number of views: <strong>
{$counter}</strong></p>";
}
add_shortcode('view','getPostViews');
本文标签: How can I show post views counter
版权声明:本文标题:How can I show post views counter? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749227544a2335791.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论