What is the current best way to call a web service from WordPress

I want to do this in WordPress, but I’m struggling to figure out the best way to do it. I want to get the data back and use it to create HTML content inside wordpress…

Guidance on exactly how to call a web service from WordPress and work with the response would be a big help!

The following is how I do it in C# using a WebClient() class.

using (var wb = new WebClient())
{
var data = new NameValueCollection();
data[“api_id”] = “xxxxx”;
data[“api_key”] = “xxxxx”;
data[“location_nid”] = “x”;
data[“api_url”] = “xxxxxxx”;
data[“version”] = “x”;
data[“format”] = “XML”;
data[“dispensaryId”] = “xxxxxx”;
Uri mjUri = new Uri(“webserviceurl”);
wb.UploadValues(mjUri, “POST”, data);
var data = Encoding.ASCII.GetString(response);
}

Kind regards,
BH

See if they have a php or JavaScript example. Either way you are doing manual code.

The Wordpress Codex is the place to start. http://codex.wordpress.org/

What you will need to do is to create a custom template. This is best done in a Child Theme that way if your theme is updated you don’t lose your custom template. Then you assign your custom template to the appropriate page to display the data. |Just place your custom code in the ‘content’ area of your page template.

Below is a simple text script that I have in a page template whilst I was doing some debugging
[php]
echo “Doing query
”;
global $wpdb;
$wpdb->show_errors();
$myrows = $wpdb->get_row(“SELECT * FROM membership WHERE ID = 1” );
echo “

”; print_r($myrows); echo “
”;
echo $myrows->member;
echo “
End query template”;
[/php]

This code connects to the Wordpress database, shows any database errors, selects from the standard membership table and then echoes out the result of the query.

Hope this helps.

Sponsor our Newsletter | Privacy Policy | Terms of Service