I’ve used WP_Query to query and display events. In some cases, though, there are no events to be displayed and I’d like to display a friendly message when that happens instead of displaying nothing – but I’m not sure how to do this. If it was a mysql query I know I could use if(mysql_num_rows($result)==0) but I don’t think that works with WP_Query. Is there something else that will work?
Thanks very much for any help you can give me.
Sarah
So, let’s say
$query
is your WP_Query object. I.e.Then you can set up ‘the loop’, by
Then to check if there are actually any returned results:
Keep in mind the logic, must be inside php tags, while the HTML markup must be outside.
Disclaimer: the syntax might not all be correct, I’ve not tested it. But check out index.php of the TwentyEleven to see what they do.