コード例 #1
0
 function get_postslist_table($author_lk)
 {
     global $wpdb, $post, $posts, $ratings;
     $ratings = array();
     $posts = array();
     //print_r($_POST);
     //exit;
     $start = $this->start . ',';
     $posts[] = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->base_prefix . "posts WHERE post_author='%d' AND post_type='%s' AND post_status NOT IN ('draft','auto-draft') ORDER BY post_date DESC LIMIT {$start} 20", $author_lk, $this->posttype));
     if (is_multisite()) {
         $blog_list = get_blog_list(0, 'all');
         foreach ($blog_list as $blog) {
             $pref = $wpdb->base_prefix . $blog['blog_id'] . '_posts';
             $posts[] = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $pref . " WHERE post_author='%d' AND post_type='%s' AND post_status NOT IN ('draft','auto-draft') ORDER BY post_date DESC LIMIT {$start} 20", $author_lk, $this->posttype));
         }
     }
     if ($posts[0]) {
         $p_list = array();
         if (function_exists('rcl_format_rating')) {
             foreach ($posts as $postdata) {
                 foreach ($postdata as $p) {
                     $p_list[] = $p->ID;
                 }
             }
             $rayt_p = rcl_get_ratings(array('object_id' => $p_list, 'rating_type' => array($this->posttype)));
             foreach ((array) $rayt_p as $r) {
                 if (!isset($r->object_id)) {
                     continue;
                 }
                 $ratings[$r->object_id] = $r->rating_total;
             }
         }
         $posts_block = rcl_get_include_template('posts-list.php', __FILE__);
         wp_reset_postdata();
     } else {
         $posts_block = '<p>' . $this->name . ' ' . __('has not yet been published', 'wp-recall') . '</p>';
     }
     return $posts_block;
 }
コード例 #2
0
function rcl_add_data_rating_posts()
{
    global $wp_query, $wpdb;
    if (!is_admin() && $wp_query->is_tax) {
        $users = array();
        $posts = array();
        $posttypes = array();
        $ratingsnone = array();
        foreach ($wp_query->posts as $post) {
            $users[$post->post_author] = $post->post_author;
            $posttypes[$post->post_type] = $post->post_type;
            $posts[] = $post->ID;
        }
        if ($posts) {
            $ratingsnone = $wpdb->get_results("SELECT post_id,meta_value FROM {$wpdb->postmeta} WHERE meta_key='rayting-none' AND post_id IN (" . implode(',', $posts) . ")");
            foreach ($ratingsnone as $val) {
                $none[$val->post_id] = $val->meta_value;
            }
        }
        $rating_authors = rcl_get_ratings(array('rating_type' => 'users', 'object_id' => $users));
        $rating_posts = rcl_get_ratings(array('rating_type' => $posttypes, 'object_id' => $posts));
        if ($rating_authors) {
            foreach ($rating_authors as $rating) {
                $rt_authors[$rating->user_id] = $rating->rating_total;
            }
        }
        if ($rating_posts) {
            foreach ($rating_posts as $rating) {
                $rt_posts[$rating->object_id] = $rating->rating_total;
            }
        }
        foreach ($wp_query->posts as $post) {
            $post->rating_author = isset($rt_authors[$post->post_author]) ? $rt_authors[$post->post_author] : 0;
            $post->rating_total = isset($rt_posts[$post->ID]) ? $rt_posts[$post->ID] : 0;
            $post->rating_none = isset($none[$post->ID]) ? $none[$post->ID] : 0;
        }
        //print_r($wp_query);
    }
}