I can’t see a problem with your if-else-statement, so I’m thinking the problem origins somewhere else. You say you get no errors, I guess you have debugging enabled. Besides, did you debug and inspect – var_dump
or print_r
it – the $wp_query
object, to see if it is really empty, has no posts.
Another thing, you are using query_posts()
, which you shouldn’t. I don’t want to replicate the argument for that, so see those two questions for more information:
- When should you use WP_Query vs query_posts() vs get_posts()?
- When to use WP_query(), query_posts() and pre_get_posts
This should clear now, better use pre_get_posts
or WP_Query
or get_posts
.
One more remark, you are using:
'post' => 'ID'
in your arguments array, but post isn’t a valid parameter – see this question for more information.