WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;


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
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

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

$response = wp_remote_request(
        '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

Your Answer


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.