API Вывод одного поста по permalink и последующих по катеориям. Readme.txt по параметрам API
This commit is contained in:
@ -10,45 +10,36 @@ function endlessPosts()
|
||||
));
|
||||
}
|
||||
|
||||
function getEndlessPostsResults($data, $paged = 1)
|
||||
function getEndlessPostsResults($data)
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
|
||||
$link = $data['permalink'];
|
||||
$result = [];
|
||||
|
||||
$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];
|
||||
$post_id = $id;
|
||||
// $category = get_the_tags($post_id);
|
||||
$result = array();
|
||||
|
||||
$requestedPost = get_post($id);
|
||||
|
||||
$result[] = ['requested-post' => $requestedPost];
|
||||
|
||||
|
||||
$args = array( // Создаем массив с параметрами запроса
|
||||
'tag__and' => $postSlugs,
|
||||
'posts_per_page' => 10,
|
||||
'paged' => $paged,
|
||||
'orderby'=>'date'
|
||||
'orderby'=>'date',
|
||||
'order'=> 'DESC'
|
||||
);
|
||||
|
||||
$posts = new WP_Query($args); // Инициализация запроса
|
||||
@ -70,13 +61,8 @@ function getEndlessPostsResults($data, $paged = 1)
|
||||
$actualTag = get_the_tags();
|
||||
$terms = get_the_category();
|
||||
$result[] = array(
|
||||
'post_id' => get_the_ID(),
|
||||
'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
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user