Add data from xml to content
-
I’m trying to connect to last.fm to get artistinfo data directly to my custom post types, it works sometimes, but I have no idea when or how.
I have defined the API in the beginning of the plugin. The problem seems to be when this should be executed.
After I create the title of my custom post type (band) it should add data from last.fm and save to database when I publish it.
function get_lastfm_artistinfo(){ global $user_ID; $my_id = $post->ID; $post_id_7 = get_post($my_id); $title = $post_id_7->post_title; //Here is it where it goes wrong, sometimes it works and sometimes it doesn't. if(get_post_type() == 'band' && $title != ''){ $band_link = str_replace('','%20',$title); $band = 'http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist='.$title.'&api_key='. API_KEY; $xml2 = simplexml_load_file($band); foreach($xml2->children() as $first){ $new_post = array( 'post_title' => $title, 'post_content' => $first->bio->content, 'post_status' => 'publish', 'post_date' => date('Y-m-d H:i:s'), 'post_author' => $user_ID, 'post_type' => 'band', 'post_category' => array(0) ); $post_id = wp_insert_post($new_post); } } } add_filter('the_content', 'get_lastfm_artistinfo');Does anyone had a similar issue?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Add data from xml to content’ is closed to new replies.