I am trying to display the latest 5 posts on my homepage using the following code:
query_posts('cat=-9&showposts=5&orderby=date&order=desc' );
I am excluding category 9 in this case. It works fine but the orderby=date is not working. I want to display the newest post first here. If you remove the category filter, i.e. cat=-9 the orderby=date works but with the category exclusion filter, it doesn't. I am stuck here and searched everywhere for a possible fix. Please help.
P.S. i also disabled all the plugins if that might have caused this but still no luck.
am i the only one having this issue?
try it also with "posts_per_page". "showposts" is deprecated as of Version 2.1 in favor of "posts_per_page". "DESC" is the default so leave it out. Do you have multiple loops on the page? try wp_reset_query above the query:
wp_reset_query();
query_posts('cat=-9&posts_per_page=5&orderby=date' );
classna
Member
Posted 12 months ago #
Tried with posts_per_page and wp_reset_query but it still does not work. This is the only loop in my index page. I do have some plugins that show posts from various categories in the sidebar. Disabling the plugins didn't solve this issue..
try it with this kind of query:
// The Query
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$the_query = new WP_Query( 'cat=-9&posts_per_page=5&orderby=date&paged=' . $page );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
classna
Member
Posted 12 months ago #
Thanks keesiemeijer for your help but this didn't work either.. i think its the category exclusion preventing it to sort. If i get rid of the category filter, the date sort works.
classna
Member
Posted 12 months ago #
Never mind, It was not working on my local machine.. Works on my live website. Still don't know why it was not working locally. here'z the code:
query_posts('&cat=-9&orderby=date&order=DESC&posts_per_page=5' );
Thanks keesiemeijer for all your help.
No problem. Glad you got it working on the live website.