Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to display data from an XML-file inside Wordpress posts, and I want to use shortcodes to do it. I have this XML-file witch I need to get the data from;

http://xml.prisguide.no/productExport.php?productId=151690

I would like to have a shortcode e.g. [prisguide id="151690"], and then the product information (limited to name, price, basic information etc) from the XML-file will display in the post.

How can I achieve this?

share|improve this question
    
Please show us your research effort about the shortcode (how you actually use it). –  kaiser Oct 8 '12 at 9:01
1  
By itself this is mostly just PHP programming issue. Please elaborate which specifics parts of this task you need help implementing in WordPress and what you have already working. –  Rarst Oct 9 '12 at 1:12
add comment

1 Answer

If this file is remotely available to you, then you should be using the HTTP API.

$response = wp_remote_request(
     'http://xml.prisguide.no/productExport.php?productId=151690'
    ,array(
        'ssl_verify' => true // If the request isn't working, try it with `false`
     )
);

You then simply go and catch the response and check if it's an error:

if ( is_wp_error( $response ) )
    // don't expose error to other users than admin
    return current_user_can( 'manage_options' ) ? $response->get_error_message() : '';

Then you go and extract the content.

$content = trim( wp_remote_retrieve_body( $response ) );
$content = new SimpleXMLElement( $content );

Now do whatever you need with your retrieved data.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.