From fd7603c63b6cd82a1b49d229035d7f7d0002036d Mon Sep 17 00:00:00 2001 From: Kr1PtunZ Date: Wed, 29 May 2024 18:29:52 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simple-theme/api-posts/api-posts.php | 55 ++++++++++++++++--- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/wp-content/themes/simple-theme/api-posts/api-posts.php b/wp-content/themes/simple-theme/api-posts/api-posts.php index 95e63ad..8896590 100644 --- a/wp-content/themes/simple-theme/api-posts/api-posts.php +++ b/wp-content/themes/simple-theme/api-posts/api-posts.php @@ -14,32 +14,69 @@ function getEndlessPostsResults($data, $paged = 1) { global $wpdb; + $link = $data['permalink']; + + $tag_slug = url_to_postid($link); //Получаем айди поста по пермалинку +// var_dump($tag_slug); + $tags = get_the_tags($tag_slug); //Получаем тэги по айди +// var_dump($tags[0]->term_id); +// die(); + $i = 0; + $postSlugs = []; + foreach ($tags as $key => $slug){ //Создаём массив с ID тэгов + $postSlugs[] += $tags[$i]->term_id; +// if ($key < count($tags) - 1) { +// $postSlugs .= ', '; +// } + $i++; + } + +// $tag_name = $tag->name; + + + $id_from_permalink = explode('/', $link); $id_from_permalink = explode('-', $id_from_permalink[3]); $id = $id_from_permalink[0]; - - $category = get_the_category($id); - + $post_id = $id; +// $category = get_the_tags($post_id); $result = array(); - $args = array( - 'category__in' => $category[0]->term_id, + $args = array( // Создаем массив с параметрами запроса + 'tag__and' => $postSlugs, 'posts_per_page' => 10, - 'paged' => $paged + 'paged' => $paged, + 'orderby'=>'date' ); - $posts = new WP_Query($args); - + $posts = new WP_Query($args); // Инициализация запроса while ( $posts->have_posts() ) { $posts->the_post(); - $terms = get_the_category(); + $tags = get_the_tags(); + $postsTags =''; + $tags = get_the_tags(); + foreach ($tags as $key => $tag){ + $postsTags .= $tags[$i]->name; + if ($key < count($tags) - 1) { + $postsTags .= ', '; + } + $i++; + } + + $actualTag = get_the_tags(); + $terms = get_the_category(); $result[] = array( 'permalink' => get_the_permalink(), 'terms' => $terms[0]->slug, + 'title' => get_the_title(), + 'author' => get_the_author(), + 'date' => get_the_date(), + 'post-body' =>get_the_content(), + 'tags' => get_the_tags()[0]->name ); }