Software Archive
Read-only legacy content

Wordpress REST Api

Robert_C_6
New Contributor I
417 Views

HI,

I am trying to use the wordpress rest api into my app, does anybody have any clue where to start?

I have tried using the docs online but the data is not showing up in the emulator.

0 Kudos
1 Solution
Diego_Calp
Valued Contributor I
417 Views

Try this:

$.getJSON("http://wpecom.robbotdev.com/blog/wp-json/wp/v2/posts",function(data){
	var len = data.length;
	for(var i = 0; i<len; i++){
	       var div_data ="<div><a href='"+data.title.rendered+"'>"+data.content.rendered+"</a></div>";
		$(div_data).appendTo("#cand");				
	}
});		

Take a look to the returned data value to understand how to parse it.

Regards

Diego

View solution in original post

0 Kudos
3 Replies
Diego_Calp
Valued Contributor I
417 Views

Hi Robert,

 

Could you post some code?

Are you using this library?

http://wpcomjs.com

Regards.

Diego

0 Kudos
Robert_C_6
New Contributor I
417 Views

Here is my current code, I had not heard of the library you mentioned. I will give it look.

 

$(document).ready( function () {
        
    
$.getJSON("http://wpecom.robbotdev.com/blog/wp-json/wp/v2/posts",function(data)
{
$.each(data.posts, function(i,data)
{
var div_data =
"<div ><a href='"+data.title+"'>"+data.content+"</a></div>";
$(div_data).appendTo("#cand");
});
}
);
return false;

}
    

0 Kudos
Diego_Calp
Valued Contributor I
418 Views

Try this:

$.getJSON("http://wpecom.robbotdev.com/blog/wp-json/wp/v2/posts",function(data){
	var len = data.length;
	for(var i = 0; i<len; i++){
	       var div_data ="<div><a href='"+data.title.rendered+"'>"+data.content.rendered+"</a></div>";
		$(div_data).appendTo("#cand");				
	}
});		

Take a look to the returned data value to understand how to parse it.

Regards

Diego

0 Kudos
Reply