I’m Using WP 3.4.2 , a child theme of twentyeleven. I have created a category called “featured media”.
I want to get and display posts which have this category.
I checked around before coming here, I found variations of the same answer, in forums. Generally I am advised to write:
$args = array('category'=> x);
get_posts($args);
I don’t know the category id. Some forums have advised me to go to Dashboard–> posts –>categories, find my category and hover over the “Edit” link, and read the category id from the status bar. My browser shows me this address: localhost/myblog/wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=7&post_type=post
This apparently means my category id is 7. The above code returns and empty array. This has become really frustrating for me. I believe the method is correct. Can anyone tell me what I’m doing wrong?
Are you setting global $post?
Heres the WordPress example from their website:
http://codex.wordpress.org/Template_Tags/get_posts