ajax подгрузка ленты друзей
-
Как лучше реализовать ajax подгрузку, в данный момент цикл проходится по всем id друзей, и по каждому id get_posts запрашивает по 5 публикаций(т.е если у меня 10 друзей и у каждого 10 постов он выведет, 5*10 = 50 постов)надо чтобы он всего запрашивал 5 публикаций и выводил их 5
Пример кода ниже
if($_GET['lang'] == 'ru' || $_GET['lang'] == '') { for ($i = 0; $i < count($id_friends); $i++) { /* Получить посты по автору */ $args = array( 'author' => $id_friends[$i], // 'meta_key' => 'rating-key', 'orderby' => 'post_date', 'offset' => 0, 'numberposts' => 5 // 'order' => 'DESC' ); $context['posts'] = get_posts($args); $arr_length = $context['posts']; // var_dump($context['posts']); // array_push($context['posts'], $array_posts); foreach ($context['posts'] as $author) { $author->views = get_post_meta($author->ID, 'viev'); $author->views = $author->views[0]; $author->post_content = get_post_meta($author->ID, 'anons_66'); // поле анонс записи $author->post_content = $author->post_content[0]; $author->like = count($wpdb->get_results("SELECT * FROM <code>wp_ratings</code> WHERE <code>rating_postid</code> = {$author->ID}")); // кол-во лайков $author->rating = $author->like * 100 + (int)$author->views; // рейтинг поста $author->amount += $author->rating; $author->category = get_the_category($author->ID); $html .= 'тут html'
- Тема «ajax подгрузка ленты друзей» закрыта для новых ответов.