A
A
Andrey Perov2015-10-14 13:25:42
PHP
Andrey Perov, 2015-10-14 13:25:42

What is the best way to do ajax loading of friends' feeds?

What is the best way to implement ajax upload? At the moment, the loop goes through all the id of friends, and for each id get_posts requests 5 posts (i.e. if I have 10 friends and each friend has 10 posts, it will display 5 * 10 = 50 posts) it needs to request a total 5 publications from all friends and brought them out, will you have to redo everything?

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 `wp_ratings` WHERE `rating_postid` = {$author->ID}")); // кол-во лайков
        $author->rating = $author->like * 100 + (int)$author->views; // рейтинг поста
        $author->amount += $author->rating;

        $author->category = get_the_category($author->ID);

        $html .= '<li class="item">
                <div class="caption">
                  <a href="' . $author->guid . '?lang=ru&pages=1">' . $author->post_title . '</a>
                </div>
                <div class="introtext">'
          . $author->post_content .
          '</div>
                <div class="b-favorites">
                  <div class="icon"></div>
                  <span title="Количество пользователей, добавивших в избранное">' . $author->rating . '</span>
                </div>
                <div class="b-category">
                  Категория: ' . $author->category[0]->cat_name . '
                </div>
                <div class="b-views">
                  <div class="icon"></div>
                  <span title="Просмотры">' . $author->views . ' просмотра</span>
                </div>
                <div class="b-likes">
                  <div class="icon"></div>
                  <span title="Нравится">' . $author->like . '</span>
                </div>
                <div class="b-date">
                  Дата добавления: ' . $author->post_date . '
                </div>
                ';
      }
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Андрей, 2015-10-14
@SnaIP

я бы для начала проверял на isset($_GET['lang']).
Потом выберите все посты с сортировкой по дате, в ID автора возмите массив ID и через IN

N
NataliaCh, 2015-10-14
@NataliaCh

А какие критерии отбора этих пяти публикаций?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question