admin管理员组文章数量:1287668
I have a datafeed, athat i want to save as a custom post type.
The idea is that based on the users geo location a dynamic header and footer should be rendered with content coming from the feed.
Here is the endpoint to access the data in the fee:
I have tried to create a custom post type based on this example.
//function for retrieving data from the external API
function fetch_from_ep_api(){
//make external HTTP request
$response = wp_remote_get(EP_API_URL);
if(!empty($response)){
//handle json
$parsed_response = wp_remote_retrieve_body($response);
$data = json_decode($parsed_response);
//debug($data)
//data structure is an array of objects with following attributes
//print_r($data[0]);
//$array_response = print_r($parsed_response);
//debug($array_response);
return $data;
}else{
throw new Exception("Could not connect to EP api");
}
}
//now i need to create a custom post type to store all the data, but i am in doubt of how to create the custom fields to do so
function create_custom_ep_country_posttype(){
$labels = array(
'name' => __('Countries', 'Post Type country name'),
'singular_name' => __('Country', 'Post type singular name'),
);
$args = array(
'show_in_admin_bar' => true
);
register_post_type('country',
array(
));
}
I don't understand how the different data types for each attribute maps in the database?
Does anybody have an idea and how to make a custom post type for the data that is in this data feed?
本文标签: Saving custom JSON as custom post type
版权声明:本文标题:Saving custom JSON as custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741316973a2371970.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论