如果你仍然使用插件WTI Likes 您可以从插件创建的表中获取direkt值,而不是将值保存到post meta。
在需要列表的位置添加此代码。现在它会打印所有喜欢的帖子。从最大到最小。
<?php
global $wpdb;
$query = "SELECT post_id, SUM(value) AS count FROM {$wpdb->prefix}wti_like_post GROUP BY post_id ORDER BY value DESC";
$posts = $wpdb->get_results( $query );
if( count( $posts ) > 0 ) {
foreach ($posts as $post) {
$post_title = get_the_title( $post->post_id );
$post_link = get_permalink( $post->post_id );
$count = $post->count;
$output .= \'<li>\';
// $count shows how many likes the post have
$output .= \'<span>\'. $count .\'</span>\';
$output .=\'<a href="\'.$post_link.\'">\'.$post_title.\'</a>\';
$output .= \'</li>\';
}
} else {
$output .= \'<li>\';
$output .= __(\'No posts.\', \'mytheme\');
$output .= \'</li>\';
}
echo $output;
?>