WP_Queryで取得したクエリを配列に入れてjsonでjsに持って行きたいのですがループの中で呼んだ$postがnullになります。
lang
1$slug = $_POST['slug']; 2 $cat = get_category_by_slug($slug); 3 4 $id = $cat->term_id; 5 $args = array( 6 'include' => $id 7 ); 8 9 $results = array(); 10 $args = array( 11 'post_type' => "post", 12 'cat' => $id, 13 'posts_per_page' => 8, 14 'order' => 'desc', 15 'orderby ' => 'modified', 16 ); 17 $blog_posts = new WP_Query($args); 18 $count = 0; 19 while ( $blog_posts->have_posts()) : $blog_posts->the_post(); 20 $hoge = $post->post_content; 21 $results[$count]["title"] = $post->post_title; 22 $count++; 23 endwhile; 24 wp_reset_postdata(); 25 26 header('Content-Type: application/json; charset=utf-8'); 27 echo json_encode($results); 28 die(); 29
上記がコードになります。
何卒よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。