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