Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Robert_C_6
New Contributor I
96 Views

Wordpress REST Api

Jump to solution

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.

Tags (2)
0 Kudos

Accepted Solutions
Diego_Calp
Valued Contributor I
96 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
96 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
96 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
97 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