jeudi 29 janvier 2015

Why am I getting posts back when I shouldnt


I have the the following variables being populated:



$posts = wp_get_recent_posts(array (
'numberposts' => 4,
'post_status' => 'publish'
));

$categoryPosts = wp_get_recent_posts(array (
'numberposts' => 4,
'category' => get_cat_ID('events'),
'post_status' => 'publish'
));


Now posts should have 1 post, the default sample hello world post. The second should be an empty an array, as this category has 0 posts associated with it.


Instead I get back (twice):



array(24) { ["ID"]=> int(1) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2015-01-28 20:49:24" ["post_date_gmt"]=> string(19) "2015-01-28 20:49:24" ["post_content"]=> string(130) "Welcome to demosite network. This is your first post. Edit or delete it, then start blogging!" ["post_title"]=> string(12) "Hello world!" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(4) "open" ["ping_status"]=> string(4) "open" ["post_password"]=> string(0) "" ["post_name"]=> string(11) "hello-world" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2015-01-28 20:49:24" ["post_modified_gmt"]=> string(19) "2015-01-28 20:49:24" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(49) "http://ift.tt/1ET0P0L" ["menu_order"]=> int(0) ["post_type"]=> string(4) "post" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "1" ["filter"]=> string(3) "raw" }


I get it back twice because I have two loops that loop over both arrays and var dump out the array.


My question is: For the $categoryPosts array Why am I getting the above array back? I should get nothing correct?





Aucun commentaire:

Enregistrer un commentaire