2017-12-25 10 views
0

wordpressからangularjsアプリケーションへメタデータを取得しています。どのように私はサーバーから離れる前にワードプレスのメタデータをunserialize unserializeすることができます。メタデータは、このようなものです:あなたがそれをシリアライズ1、ある場合には、クライアントに送信する前にwordpressを使用しているときにwordpressメタデータをunserializeするanglejsでREST APIを使用する

["a:29:{s:8:\"subtitle\";s:14:\"iphone Showroom\";s:12:\"featuredItem\";s:1:\"0\";s:10:\"headerType\";s:3:\"map\";s:11:\"headerImage\";s:0:\"\";s:12:\"headerHeight\";s:0:\"\";s:3:\"map\";a:7:{s:7:\"address\";s:23:\"Mod city\";s:8:\"latitude\";s:13:\"26.4819543403\";s:9:\"longitude\";s:13:\"76.7334592342\";s:10:\"streetview\";s:1:\"0\";s:9:\"swheading\";s:2:\"90\";s:7:\"swpitch\";s:1:\"5\";s:6:\"swzoom\";s:1:\"1\";}s:9:\"telephone\";s:12:\"074002344777\";s:19:\"telephoneAdditional\";s:0:\"\";s:5:\"email\";s:26:\"[email protected]\";s:9:\"showEmail\";s:1:\"1\";s:15:\"contactOwnerBtn\";s:1:\"1\";s:3:\"web\";s:0:\"\";s:12:\"webLinkLabel\";s:0:\"\";s:19:\"displayOpeningHours\";s:1:\"1\";s:18:\"openingHoursMonday\";s:19:\"09:00 AM - 08:00 PM\";s:19:\"openingHoursTuesday\";s:19:\"09:00 AM - 08:00 PM\";s:21:\"openingHoursWednesday\";s:19:\"09:00 AM - 08:00 PM\";s:20:\"openingHoursThursday\";s:19:\"09:00 AM - 08:00 PM\";s:18:\"openingHoursFriday\";s:19:\"09:00 AM - 08:00 PM\";s:20:\"openingHoursSaturday\";s:19:\"09:00 AM - 08:00 PM\";s:18:\"openingHoursSunday\";s:19:\"09:00 AM - 08:00 PM\";s:16:\"openingHoursNote\";s:0:\"\";s:18:\"displaySocialIcons\";s:1:\"0\";s:26:\"socialIconsOpenInNewWindow\";s:1:\"0\";s:11:\"socialIcons\";s:0:\"\";s:14:\"displayGallery\";s:1:\"1\";s:7:\"gallery\";a:2:{i:0;a:2:{s:5:\"title\";s:0:\"\";s:5:\"image\";s:68:\"http://www.example.com/wp-content/uploads/2017/02/DSCN0366-min.jpg\";}i:1;a:2:{s:5:\"title\";s:0:\"\";s:5:\"image\";s:68:\"http://www.example.com/wp-content/uploads/2017/02/DSCN0365-min.jpg\";}}s:15:\"displayFeatures\";s:1:\"0\";s:8:\"features\";s:0:\"\";}"] 
+2

残りのAPIを取得する前に、シリアル化を解除する必要があります。 PHPだけがシリアル化された文字列を理解し、JavaScriptで独自のパーサーを書くことは悪い考えです。サーバーを離れる前に、シリアル化を解除する方法に質問を変更したい場合があります。しかし、まず自分自身を調べるべきです。 –

答えて

0

私はいくつかの調査を行い、解決策を見つけました。このようにサーバーサイドでこれを行う必要があります。 あなたのfunction.phpを編集し、すべてのJSONオブジェクト内のメタデータをシリアライズ取得します。このコードの後に​​、この

add_action('rest_api_init', 'create_api_custom_meta_field'); 

function create_api_custom_meta_field() { 
    register_rest_field('custom-post', 'post_all_meta_fields', array(
     'get_callback' => 'get_post_meta_for_api', 
     'schema' => null, 
     )); 
} 


function get_post_meta_for_api($object) { 
    //get the id of the post object array 
    $post_id = $object['id']; 

    //return the post meta 
    return get_post_meta($post_id); 
} 

のようなコードを使用する必要があります。 :)

関連する問題