Title: json pull to insert into a post
Last modified: August 30, 2016

---

# json pull to insert into a post

 *  [mpellas](https://wordpress.org/support/users/mpellas/)
 * (@mpellas)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/json-pull-to-insert-into-a-post/)
 * Hello,
 * I’ve got a handle on the non Worspress PHP (I’ve been experimenting in PHPfiddle.
   org) but am having trouble translating it to functionality in wordpress.
 * I’m looking to get a json pull from [http://aggrenda.com/mpellas/michael-pellas/events.json](http://aggrenda.com/mpellas/michael-pellas/events.json)
   and post the data (address, description, photo url, website) in a scheduled wordpress
   post.
 * I’ve been able to get a json string but haven’t been able to parse it in wordpress.
 * here is the latest code:
 *     ```
       add_shortcode('aggrenda', 'requestAggrendaEvents');
   
       		function requestAggrendaEvents() {
       			$json = wp_remote_get("http://aggrenda.com/mpellas/michael-pellas/events.json");
       			$data = json_decode($json, true);
       			return $data['events'];
       		}
   
       		function getPostInfo($aggrendaEvent) {
       			return array(
       				"title" => $aggrendaEvent['title'],
       				"description" => $aggrendaEvent['description'],
       			);
       		}
   
       		// Get the aggrenda events as an associative array
       		$aggrendaEvents = requestAggrendaEvents();
   
       		// Get the WordPress post information for the "next" event in Aggrenda
       		$postInfo = getPostInfo($aggrendaEvents[0]);
   
       		// TODO: Create a post using $postInfo
       		echo $postInfo['title'], '';
       		echo $postInfo['description'], '';
   
       		// See what exactly is in $postInfo right now
       		var_dump($postInfo);
       ```
   
 * What am I missing?

Viewing 1 replies (of 1 total)

 *  [Gagan Deep Singh](https://wordpress.org/support/users/gagan0123/)
 * (@gagan0123)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/json-pull-to-insert-into-a-post/#post-6470476)
 * **mpellas**
 * **wp_remote_get** returns you with an array, not JSON encoded string as you’re
   expecting, that goes for “What am I missing” part.
 * Same thing happened with me when I first used **wp_remote_get**, then I learnt
   reading [codex](https://codex.wordpress.org/Function_Reference/wp_remote_get)
 * Also, WordPress functions are not available in PHPFiddle(or thats what I believe).
 * Your code will work in a WordPress site, after proper handling of data returned
   by wp_remote_get.
 * Do let me know if it worked or not for you.

Viewing 1 replies (of 1 total)

The topic ‘json pull to insert into a post’ is closed to new replies.

## Tags

 * [json](https://wordpress.org/support/topic-tag/json/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Gagan Deep Singh](https://wordpress.org/support/users/gagan0123/)
 * Last activity: [10 years, 8 months ago](https://wordpress.org/support/topic/json-pull-to-insert-into-a-post/#post-6470476)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
