Skip Navigation

[Resolved] Offer posts in XML format

This support ticket is created 3 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 5 replies, has 2 voices.

Last updated by umbertoZ 3 years, 8 months ago.

Assisted by: Shane.

Author
Posts
#2006371

Hi, I need to offer a loop of my custom post type 'properties' in XML format to a third party system by an URL.

Can you give me an idea how to do it?

I built a View to generate the correct XML format, something like this:

<properties>

<wpv-loop>
    <property>
        <id>[wpv-post-id]</id> 
        <reference>[types field='ref'][/types]</reference>
    </property>
</wpv-loop>
</properties>

How can I offer this loop in an URL like mydomain.com/properties.xml?

The final output should be like:

<?xml version="1.0" ?>

<properties>

    <property>
        <id>3333</id> 
        <reference>k444</reference>
    </property>

    <property>...</property>

</properties>

thanks

#2006603

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Given that this is done in a view, the view will need to be added to a page. It is not possible to use the view only to create and xml only page where just the xml is being displayed on the page without any other formatting from the theme.

Perhaps i'm not 100% clear on this issue but i'm assuming that you want a dedicated xml page without any of the theme's html markup.

Thanks,
Shane

#2006803

Hi, that's the idea, I want a dedicated xml page.

I found this code to gennerate an XML page that I've integrated in a shortcode:

add_shortcode('properties-xml', 'properties_xml');
function properties_xml( $atts ) {
  
  $dom = new DOMDocument();

  $dom->encoding = 'utf-8';
  $dom->xmlVersion = '1.0';
  $dom->formatOutput = true;
  $xml_file_name = 'properties.xml';

  $root = $dom->createElement('properties');
  
  $property_node = $dom->createElement('property');

  $attr_property_id = new DOMAttr('property_id', '5467');
  $property_node->setAttributeNode($attr_property_id);

  $child_node_title = $dom->createElement('Title', 'House 1');
  $property_node->appendChild($child_node_title);

  $child_node_year = $dom->createElement('Date', '2012/02/02');
  $property_node->appendChild($child_node_date);

  $root->appendChild($property_node);
  $dom->appendChild($root);

  $dom->save($xml_file_name);

  echo "<a href='<em><u>hidden link</u></em> been successfully created";
}

It works, but now I need to integrate inside it a loop of my custom post type. I'd like to populate it with my View, but I don't know if it is possible.

#2007481

Hey, I'm creating by myself the PHP loop, it seems it works fine. The only issue is that I'd need to display the post-content in all the languages in the same xml, something like this:

<property>
     <id></id> 
     <description language="en"></description> 
      <description language="fr"></description>
      <description language="es"></description>
      <description language="de"></description>
</property>

I can get the current language post content by get_the_content(), but how can I get the different translations of the post?

cheers

#2007577

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Umberto,

Happy to see that you're making some progress, if you are using WPML to do the translations then you should be looking at this function below in order to get the information from the other translated languages.

https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/?wpvhookcategory=retrieving-localized-content&wpv-hook=0&wpv_post_search&wpv_filter_submit=Submit#hook-605256

Please let me know if this helps. Also it should be noted that my WPML knowledge is quite limited so I wouldn't be able to provide much assistance on translation queries.

Thanks,
Shane

#2007675

My issue is resolved now. Thank you!