商品名3
商品説明文が入ります。商品説明文が入ります。商品説明文が入ります。商品説明文が入ります。商品説明文が入ります。
商品説明文が入ります。商品説明文が入ります。商品説明文が入ります。商品説明文が入ります。商品説明文が入ります。商品説明文が入ります。商品説明文が入ります。商品説明文が入ります。
白米、発芽玄米、大豆(自然栽培)、馬鈴薯澱粉(北海道産)、有機コーンスターチ、米粉、有機オートミール
/* ========================================================= * /store 側:REST API「店舗ターム付き・最新お知らせ一覧」を返す * - store タクソノミーが付いた post のみ * - 日付の新しい順に limit 件 * - 返却:店舗名/店舗リンク/お知らせタイトル/URL/日付/抜粋/サムネ * ========================================================= */ add_action('rest_api_init', function () { register_rest_route('kp/v1', '/latest-store-news', [ 'methods' => 'GET', 'permission_callback' => '__return_true', 'callback' => function (WP_REST_Request $req) { $tax = defined('KP_STORE_TAX') ? KP_STORE_TAX : 'store'; $limit = max(1, min(20, (int) $req->get_param('limit') ?: 8)); // 最大20に制限 // キャッシュ(5分) $cache_key = 'kp_latest_store_news_' . $limit; $cached = get_transient($cache_key); if ($cached !== false) return $cached; $q = new WP_Query([ 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => $limit, 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'orderby' => 'date', 'order' => 'DESC', 'tax_query' => [[ 'taxonomy' => $tax, 'operator' => 'EXISTS', // 店舗タームが付いている投稿のみ ]], ]); $out = []; foreach ($q->posts as $p) { $terms = get_the_terms($p->ID, $tax); $term = (!is_wp_error($terms) && !empty($terms)) ? array_shift($terms) : null; $store_link = $term ? get_term_link($term) : ''; if (is_wp_error($store_link)) $store_link = ''; // 店舗のお知らせ一覧URL(あなたの関数があればそれを使う) $store_news_link = ''; if ($term && function_exists('kp_get_store_news_url')) { $store_news_link = kp_get_store_news_url($term); } $out[] = [ 'store' => $term ? [ 'term_id' => $term->term_id, 'slug' => $term->slug, 'name' => $term->name, 'link' => $store_link, 'news' => $store_news_link, ] : null, 'post' => [ 'id' => $p->ID, 'title' => get_the_title($p), 'url' => get_permalink($p), 'date' => get_the_date('Y-m-d', $p), 'excerpt' => wp_trim_words(get_the_excerpt($p), 32, '…'), 'thumb' => get_the_post_thumbnail_url($p, 'medium') ?: '', ], ]; } wp_reset_postdata(); set_transient($cache_key, $out, 5 * MINUTE_IN_SECONDS); return $out; }, ]); });