Solved

How do I format the output from WP Rest API?

Posted on 2016-11-21
1
53 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Filter wordpress query 3 36
Webservice response iSeries 1 31
WordPress 4.7.1 where is robots.txt file 5 30
Little bit of help styling my heading 3 19
How to install BuddyPress on your self-hosted WordPress site It’s been called everything from “social networking in a box” to “Facebook without the terms of service,” but until Feb. 16, BuddyPress was a relatively unknown outside the WordPress MU…
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 insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …

772 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