I have a page that lists all posts with a certain category “news”. The first result is always itself – the page! The page doesn’t even have a category but for some reason is listed as one. I only want to retrieve ‘posts’.
My query is:
query_posts( array ( 'category_name' => 'news', 'posts_per_page' => 4, 'orderby' => 'date', 'order' => 'ASC', 'post_type' => 'post' ) );
The resulting page can be seen here:
http://vl.social-gamer.com/news-blog/
I appreciate any help. I’m a bit of a WP noob still.
Thanks!
If what you’re trying to do is just get a list of categories, then I’d suggest a function already inside of WordPress called
wp_list_categories()
. Here’s the documentation on that particular function.Keep in mind, this will also
echo
out the categories, not just retrieve them. I find myself using this function quite often:However, if you’re looking to find just the “posts” of a certain category and not the “pages” as well then understand that pages in WordPress are nearly the same thing as posts in WordPress. Pages for one can’t have a category, but posts can. Posts are sorted by date, and pages are not. There’s some discrepancies, but for all intents and purposes, there’s not a huge difference in how you should code between the two. Here’s some more information on that discussion.
EDIT
The author of the post appears to have this problem due to an improper file structure. For references to a good fule structure please see this link.