oflcad
oflcad

Reputation: 515

How to render content of wordpress api?

I am creating a mobile app for a wordpress solution, while studying wordpress rest api, I have found a problem with the way the json schema is rendered;

while /wp-json/wp/v2/posts displays all posts but it is in this format

"title": {
    "rendered": "testing rest api & #8220;tesint-restAP& #8221;"
 }, 

How to extract the actual content from response.data.content because it came as html version with tags and such ???.enter image description here

Upvotes: 3

Views: 3670

Answers (3)

dev-katiyar
dev-katiyar

Reputation: 41

Just use content of "rendered" as value for innterHTML property of element like div. It will work.

let htmlStr = `<p><em>&#8220;Anatomy of a Bear Market&#8221;</em> by Russell Napier is a <em>&#8220;must-read</em>&#8221; manuscript. Given current market dynamics, a review seems timely. As my colleague, Richard Rosso, CFP, previously penned:</p>`
let ele = document.getElementById('target');
ele.innerHTML = htmlStr;
<div id="target"></div>

Upvotes: 0

Bart VdA
Bart VdA

Reputation: 638

Tip for .NET Developers

When using http://restsharp.org/ in .NET to call the API, no parsing was required on the content.

Upvotes: 1

hakki
hakki

Reputation: 6527

First, get your json data with its html tags, then

var StrippedString = OriginalString.replace(/(<([^>]+)>)/ig,"");

Upvotes: 0

Related Questions