Files
profile/inc/popular-json.php
Profile Profile ed4d79b706 add files inc
2026-03-09 20:51:08 +03:00

43 lines
1.2 KiB
PHP

<?php
$json_path = CACHED_TEMPLATE.'json';
$ids = array_map(
function ($item) { return $item->id; },
json_decode(get_option("ppp_options") ?: '[]')
);
$posts = get_posts([
"post_type" => ["anew", "yellow"],
"post_status" => "publish",
"posts_per_page" => 20,
"ignore_sticky_posts" => true,
"post__in" => $ids,
"orderby" => "post__in",
"meta_query" => [[
"key" => "_thumbnail_id",
"compare" => "EXISTS"
]]
]);
$data = array_map(function($post) {
$thumbnail = get_the_post_thumbnail_url($post->ID, 'thumb-264');
return [
'id' => $post->ID,
'title' => get_the_title($post->ID),
'link' => get_permalink($post->ID),
'thumbnail' => $thumbnail ?: wp_get_attachment_image_url(1357368, 'thumb-264'),
'alt' => get_the_title($post->ID)
];
}, $posts);
// Создаем директорию если не существует
if (!file_exists($json_path)) {
wp_mkdir_p($json_path);
}
$json_file = $json_path.'popular';
file_put_contents($json_file, json_encode($data, JSON_UNESCAPED_UNICODE));