Jquery and Wordpress Json plugin - how do you get selected output from object?
Sorry made a mess of my first post - here it is again.
Hi there, I'm hoping this is simple:
I'm using the Json plugin in a Wordpress blog, the below code spits out all the posts. Here it's showing the title and excerpt for each post (I can access the ID number too if I want). I'd like to just be able to display certain posts based on their ID. I hoped to use an if statement to select certain posts but it doesn't work - see my code at the very bottom.
Any help solving this would be appreciated.
function listPosts(data) {
var output='<ul data-role="listview" data-filter="true">';
$.each(data.posts,function(key,val) {
output+='<li>';
output+='<h3>' + val.title + '</h3>';
output+='<p>' + val.excerpt + '</p>';
output+='</li>';
}); // go through each post
output+='</ul>';
$('#postlist').html(output);
} // lists all the posts
>>>>>>>>>>>>>>
MY ATTEMPT BELOW - doesn't work:
function listPosts(data) {
var output='<ul data-role="listview" data-filter="true">';
$.each(data.posts,function(key,val) {
if (val.id['56']) && (val.id['61']){
output+='<li>';
output+='<h3>' + val.title + '</h3>';
output+='<p>' + val.excerpt + '</p>';
output+='</li>';
}
}); // go through each post
output+='</ul>';
$('#postlist').html(output);
} // lists all the posts