Title: XML with api to wordpress
Last modified: November 5, 2024

---

# XML with api to wordpress

 *  [Goos Mante](https://wordpress.org/support/users/meganmante/)
 * (@meganmante)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/)
 * Hello, I have the following problem. I would like to put the traffic information
   from our national provider on my site. I have already tried various plug-ins,
   but it didn’t work. I also tried chat GPT, but that doesn’t work either. Would
   anyone like to help me with it? The script is here, but I can’t get it to appear
   on the site now
 * [https://cris-admin.anwb.nl/export-api/v1/pqfeed/latest](https://cris-admin.anwb.nl/export-api/v1/pqfeed/latest)
   _[
   private information removed by moderator]
 * Has anyone a solution
 * Regards
 * Goos
    -  This topic was modified 1 year, 7 months ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fxml-with-api-to-wordpress%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 15 replies - 1 through 15 (of 39 total)

1 [2](https://wordpress.org/support/topic/xml-with-api-to-wordpress/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/xml-with-api-to-wordpress/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/xml-with-api-to-wordpress/page/2/?output_format=md)

 *  [tarhe](https://wordpress.org/support/users/obt28/)
 * (@obt28)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/#post-18115467)
 * Hello [@meganmante](https://wordpress.org/support/users/meganmante/)
 * To be able to get the content from the above API you’ll need to develop a custom
   plugin that can query the XML API – [https://cris-admin.anwb.nl/export-api/v1/pqfeed/latest](https://cris-admin.anwb.nl/export-api/v1/pqfeed/latest)
   and the display the response via shortcode.
 * This can be typically done by consulting a WordPress developer. To help you get
   started if it’s something you’d like to do yourself you can work with the sample
   plugin below as a start point. The plugin is currently working when i tested 
   it, your API key is already added to the plugin code
 * Save the above code as a PHP file e.g., `anwb-traffic-info.php` inside your plugins
   directory. then enable the `anwb-traffic-info` plugin.
 * Once it’s enabled, add the shortcode `[anwb_traffic_info]` to any page or post
   where you want the traffic data to appear. Please ensure you work further on 
   the plugin to improve the functionality before using it on a production site.
 *     ```wp-block-code
       <?php/*Plugin Name: ANWB Traffic InfoDescription: Displays live traffic information from ANWB API using an API key.Version: 1.0Author: Your Name*/function fetch_and_display_anwb_traffic_info() {    // Define the cache key and expiration time    $cache_key = 'anwb_traffic_info_cache';    $cache_expiration = HOUR_IN_SECONDS; // Cache duration (1 hour)    // Try to get the cached data    $cached_data = get_transient($cache_key);    if ($cached_data !== false) {        // Return the cached data if it exists        return $cached_data;    }    $api_url = 'https://cris-admin.anwb.nl/export-api/v1/pqfeed/latest';    $api_key = 'xxxxxxxxxxxxxxxxx';    // Set up the request with the API Key in the headers    $response = wp_remote_get($api_url, [        'headers' => [            'x-api-key' => $api_key        ]    ]);    if (is_wp_error($response)) {        return 'Error retrieving traffic data: ' . $response->get_error_message();    }    $xml_data = wp_remote_retrieve_body($response);    // Check if we have data    if (empty($xml_data)) {        return 'No data received from the API.';    }    // Parse the XML response    $xml = simplexml_load_string($xml_data);    if (!$xml) {        return 'Error parsing traffic data.';    }    // Start output buffer to capture HTML content    ob_start();    echo '<div class="anwb-traffic-info">';    foreach ($xml->Sections->Section->Messages->Message as $message) {        echo '<div class="traffic-message">';                // Dynamically get and display each field        foreach ($message as $key => $value) {            // Skip empty fields            if (!empty($value)) {                echo '<strong>' . esc_html($key) . ':</strong> ' . esc_html($value) . '<br>';            }        }        echo '</div><hr>';    }    echo '</div>';    // Get buffer contents and clean buffer    $output = ob_get_clean();    // Cache the output for future requests    set_transient($cache_key, $output, $cache_expiration);    return $output;}// Register a shortcode to display the data on any page/postadd_shortcode('anwb_traffic_info', 'fetch_and_display_anwb_traffic_info');
       ```
   
    -  This reply was modified 1 year, 7 months ago by [tarhe](https://wordpress.org/support/users/obt28/).
    -  This reply was modified 1 year, 7 months ago by [tarhe](https://wordpress.org/support/users/obt28/).
    -  This reply was modified 1 year, 7 months ago by [tarhe](https://wordpress.org/support/users/obt28/).
    -  This reply was modified 1 year, 7 months ago by [tarhe](https://wordpress.org/support/users/obt28/).
    -  This reply was modified 1 year, 7 months ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).
 *  Thread Starter [Goos Mante](https://wordpress.org/support/users/meganmante/)
 * (@meganmante)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/#post-18115602)
 * Hi
 * I am not so good with php was wondering if you could help me out on this
 * Goos
 *  [tarhe](https://wordpress.org/support/users/obt28/)
 * (@obt28)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/#post-18115676)
 * Hi [@meganmante](https://wordpress.org/support/users/meganmante/)
 * We’re unable to help further than this but for now the plugin above should work
   90% to output the response from the above API when you install the plugin add
   the shortcode `[anwb_traffic_info]` to any page or post where you want the traffic
   data to appear.
 * You’re welcome to reach out to a developer to help expand the functionality further,
   just wanted to demonstrate how you can make it work.
 *  Thread Starter [Goos Mante](https://wordpress.org/support/users/meganmante/)
 * (@meganmante)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/#post-18115679)
 * Ok i see . Where must i put the php code i am usin Elementor
 * Goos
 *  [tarhe](https://wordpress.org/support/users/obt28/)
 * (@obt28)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/#post-18116015)
 * [@meganmante](https://wordpress.org/support/users/meganmante/)
 * You can follow the steps here on the [link ](https://powerpackelements.com/how-to-add-shortcode-in-wordpress-with-elementor/)
   to add a shortcode on your page/post from Elementor.
 * I hope that helps 🙂
 *  Thread Starter [Goos Mante](https://wordpress.org/support/users/meganmante/)
 * (@meganmante)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/#post-18116098)
 * Yes i understand that but how can i add the php code in to elementor
 *  [tarhe](https://wordpress.org/support/users/obt28/)
 * (@obt28)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/#post-18116191)
 * [@meganmante](https://wordpress.org/support/users/meganmante/),
 * Please follow the steps below to use the plugin.
    - Download the plugin from here – [https://file.io/RfKuedub1CqT](https://file.io/RfKuedub1CqT)
    - Install and activate the plugin from **WordPress admin** > [plugins ](https://poprockradio.nl/wp-admin/plugins.php)
    - Add this shortcode `[anwb_traffic_info]` on elementor with the steps [here ](https://elementor.com/help/how-to-use-shortcodes/)
      to any of your page/post and save your page
 * Once you follow the above process you see the traffic data displaying on the 
   page/post you added it to.
 *  Thread Starter [Goos Mante](https://wordpress.org/support/users/meganmante/)
 * (@meganmante)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/#post-18116205)
 * Hmm recieve this message
 * The transfer you requested has been deleted
 *  [tarhe](https://wordpress.org/support/users/obt28/)
 * (@obt28)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/#post-18116366)
 * Look like the link got expired. Please [download here](https://toffeeshare.com/c/XnZapMeWQX)
   as soon as you can before it expires again.
 *  Thread Starter [Goos Mante](https://wordpress.org/support/users/meganmante/)
 * (@meganmante)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/#post-18116373)
 * i am seeimg this now
 * [https://poprockradio.nl/anwb/](https://poprockradio.nl/anwb/)
 *     ```
       Organization: ANWB/NDW/NLRWS_0004371023
       TrafficType: 0
       Country: NL
       RoadNumber: A2
       SegID: 3104
       SegStartName: 's-Hertogenbosch
       SegEndName: Utrecht
       FromCarriagewayType: ConnectingCarriageWay
       ToCarriagewayType: ConnectingCarriageWay
       MainLocation: A2 's-Hertogenbosch richting Utrecht,
       TMCPriLoc: 7988
       TMCPriName: knp. Oudenrijn naar de A12 richting Arnhem
       HMPriLoc: 63.6
       CoordPriLoc:
       CoordSecLoc:
       DetailLoc: bij knp. Oudenrijn naar de A12 richting Arnhem
       CodeDirection: 1
       Stop: 2024-11-06T04:00:00
       Events:
       FullText: A2 's-Hertogenbosch richting Utrecht, bij knp. Oudenrijn naar de A12 richting Arnhem wegwerkzaamheden, verbindingsweg dicht. Verwachte eindtijd: 06 november 2024 05:00
       ```
   
 * How can we get only the text
 * FullText: A2 ‘s-Hertogenbosch richting Utrecht, bij knp. Oudenrijn naar de A12
   richting Arnhem wegwerkzaamheden, verbindingsweg dicht. Verwachte eindtijd: 06
   november 2024 05:00`
 *  Thread Starter [Goos Mante](https://wordpress.org/support/users/meganmante/)
 * (@meganmante)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/#post-18116374)
 * It is working but now we need to get the text
 * FullText: information with every report how can we get that
 * Goos
 *  Thread Starter [Goos Mante](https://wordpress.org/support/users/meganmante/)
 * (@meganmante)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/#post-18116387)
 * Like this site has must it on our website
 * [https://www.omroepwest.nl/verkeer](https://www.omroepwest.nl/verkeer)
 * Goos
 *  [tarhe](https://wordpress.org/support/users/obt28/)
 * (@obt28)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/#post-18116390)
 * [@meganmante](https://wordpress.org/support/users/meganmante/)
 * Good to know you were able to get the plugin to work to modify the plugin to 
   display only the `FullText` field from each traffic message, you can update the`
   foreach` loop to check specifically for that field.
   You can download the new 
   modified plugin [here](https://toffeeshare.com/c/4flQvABARm) that will display
   the `FullText` field only. You just need to update the previous plugin with this
   new version to see only the `FullText` field on the response.
    -  This reply was modified 1 year, 7 months ago by [tarhe](https://wordpress.org/support/users/obt28/).
    -  This reply was modified 1 year, 7 months ago by [tarhe](https://wordpress.org/support/users/obt28/).
 *  Thread Starter [Goos Mante](https://wordpress.org/support/users/meganmante/)
 * (@meganmante)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/#post-18116398)
 * must i use [FullText]
 *  [tarhe](https://wordpress.org/support/users/obt28/)
 * (@obt28)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/#post-18116408)
 * Yes, since the XML data from the API contains a `<FullText>` field that includes
   the primary information you want to display, then accessing `$message->FullText`
   is the way to go.

Viewing 15 replies - 1 through 15 (of 39 total)

1 [2](https://wordpress.org/support/topic/xml-with-api-to-wordpress/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/xml-with-api-to-wordpress/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/xml-with-api-to-wordpress/page/2/?output_format=md)

The topic ‘XML with api to wordpress’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 41 replies
 * 2 participants
 * Last reply from: [Goos Mante](https://wordpress.org/support/users/meganmante/)
 * Last activity: [1 year, 5 months ago](https://wordpress.org/support/topic/xml-with-api-to-wordpress/page/3/#post-18206205)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
