"It doesn't work and I can't figure out why" is kind of vague.
What have you tested so far? Where did you stop figuring out? What did you figure out?
I'm not familiar with WordPress so much, but if above is all your code then I think it won't work because no database connection is being made. But I guess that is not your problem, since I guess this is only a snippet.
So what you would do then is:
- Figure out if there is any error message. Is your PHP error logging on and if so, is it being printed to the screen (you could enable that if not) or is it being logged to a logfile?
- If your errorlogging is OK and there is no errormessage than you'd have to figure it out yourself by debugging:
- What happens if you run a static query to the database? For example: first run a query in PHPMyAdmin or any other tool you use and make sure the query works. Then you run that same query from your code and see if that works too. If not: you know the query is OK, so it must be your database connection, or the way you use the database wrapper.
- If a static query works fine, die() the query you're using in the loop above. Then copy that query and run it from your databasetool to see if it works there.
- Etc.
That's how you debug. Can you continue from there?
$query_results
an empty array? Does the query result in an error? – Dave Chen Jul 20 at 23:35