• hi
    i am used <?php echo get_related_author_posts(); ?> for related author posts.

    Now
    I am using the following code to count visitors.

    add_filter( 'pre_option_link_manager_enabled', '__return_true' );
    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 "no visit";
        }
        return $count.' visit';
    }
    
    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);
        }
    }
    add_filter('manage_posts_columns', 'posts_column_views');
    add_action('manage_posts_custom_column', 'posts_custom_column_views',5,2);
    function posts_column_views($defaults){
        $defaults['post_views'] = __('visit');
        return $defaults;
    }
    function posts_custom_column_views($column_name, $id){
        if($column_name === 'post_views'){
            echo getPostViews(get_the_ID());
        }
    }

    now
    How to show 10 best(or Popular) posts your author (based on Visit (code above)) in my site?
    1- I do not post ID. ID get.
    2- no plugin.

  • The topic ‘View Post a author’ is closed to new replies.