2011-09-15 88 views
0

我想要使用此功能如何使用post_views_count函數對帖子進行排序(按視圖排序)?

我使用function.php此代碼來獲取後觀看次數

<?php 
function getPostViews($postID){ 
$count_key = 'post_views_count'; 
$count = get_post_meta($postID, $count_key, true); 
if($count==''){ 
    delete_post_meta($postID, $count_key); 
    add_post_meta($postID, $count_key, '0'); 
    return "0 View"; 
} 
return $count.' Views'; 
} 
function setPostViews($postID) { 
$count_key = 'post_views_count'; 
$count = get_post_meta($postID, $count_key, true); 
if($count==''){ 
    $count = 0; 
    delete_post_meta($postID, $count_key); 
    add_post_meta($postID, $count_key, '0'); 
}else{ 
    $count++; 
    update_post_meta($postID, $count_key, $count); 
} 
} 
?> 

像這樣

&orderby=comment_count&order=desc 
&v_sortby=views&v_orderby=desc 

回答

1

職位(排序視圖)排序我想你可以使用這個查詢:

$new_posts = new WP_Query(array('meta_key' => 'post_views_count', 'orderby'=> 'meta_value', 'order' => 'desc')); 
相關問題