WP REST APIで、WordPressより記事などを取得して静的サイトに表示をさせようと考えています。
現状カスタム投稿の取得はできているのですが、下記点において取得の仕方が分からず苦戦しております。
・記事のカテゴリデータが取得できない
・アドバンスドカスタムフィールドプロを使用しているのですが、そのデータが取得できない
現状WP REST APIはWordpressのバージョン上デフォルトで入っております。
ACF to REST APIはインストール有効化済になります。
WP REST APIは下記JSで取得表示しています。
lang
1$(function(){ 2 3 //HTMLを生成 4 5 $html_set = ''; 6 7 $.getJSON("http://example.com/wp-json/wp/v2/news?_embed", function(data){ 8 9 $html_set = '<style>' + 10 'ul.wp_api-unit{display:block;}'+ 11 'ul.wp_api-unit li{clear:both; margin-bottom:15px; padding-bottom: 15px;border-bottom:1px dotted #cccccc;}'+ 12 'ul.wp_api-unit a{width:100%;display:block;}'+ 13 'ul.wp_api-unit .thumbnail{display:inline-block;width:28%;margin:0;padding:0 2% 0 0; vertical-align:top;}'+ 14 'ul.wp_api-unit .contents {display:inline-block;width:70%;}'+ 15 'ul.wp_api-unit .contents h1{font-size:1.6em; margin:0; paddin-bottom: 15px; margin:0; padding:0;}'+ 16 'ul.wp_api-unit .contents p{text-align: right; width:100%;}' + 17 '</style>'; 18 19 $html_set += '<div>'; 20 21 $(data).each(function(){ 22 23 $title = this.title.rendered; 24 $excerpt = this.excerpt.rendered; 25 $date = new Date(this.date_gmt); 26 $month = $date.getMonth()+1; 27 $date_set = $date.getFullYear() + '.' + $month + '.' + $date.getDate() + '.'; 28 $thumbnail_src = this._embedded["wp:featuredmedia"][0].media_details.sizes.full.source_url; 29 30 $html_set += '<div class="new-news bgimg pos-r" style="background-image: url('+ $thumbnail_src +')">' + '<a href="' + this.link + '" class="pos-a-area"></a>' + '<div class="event-text-wrap new-text-wrap pos-a">' + '<h4>' + $title + '</h4>' + '<p class="release-date">' + $date_set + '</p>' + '<p class="new-release-text">' + $excerpt +'</p>' + '</div>' + 31 32 '</div>'+ 33 ''; 34 }) 35 $html_set += '</div>'; 36 $($html_set).appendTo('.newRelease'); 37 }) 38});
$(data).each(function()
以下で取得データを代入し表示させているのですが、ここの取得の方法が分からず苦戦しております。
何卒ご教授よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/02 00:42
2017/06/02 02:11
2017/06/02 03:36