Solved

How do I format the output from WP Rest API?

Posted on 2016-11-21
1
20 Views
Last Modified: 2016-11-25
I have a Wordpress website and i am trying to display content from it on another webpage.
To do this i have installed the WP Rest API plugin (http://v2.wp-api.org/)
I have also installed WP REST API Filter Items plugin (https://github.com/bueltge/wp-rest-api-filter-items)

Using these 2 plugins i am able to retrieve posts from my wordpress website using a GET request, like this:
http://www.heavenlygardens.org.uk/wp-json/wp/v2/posts/1103?items=content

You can see it in action at this url by clicking on the marker:
http://www.heavenlygardens.org.uk/maps/7/7.html

As you can see the following content is returned:
{"content":{"rendered":"<p>This is a demo &#8211; this info should display on the Profile tab!<\/p>\n","protected":false}}

How do i format the output, so that only the content within the <p></p> tags is displayed?
0
Comment
Question by:Daniish
1 Comment
 
LVL 25

Accepted Solution

by:
James Rodgers earned 500 total points
ID: 41897592
quick and dirty


<?php

$obj=json_decode('{"content":{"rendered":"<p>This is a demo &#8211; this info should display on the Profile tab!<\/p>\n","protected":false}}');
$rendered=strip_tags($obj->content->rendered);
echo $rendered;

?>

Open in new window

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now