Custom $wpdb Query for Custom Post Type by Category

Don’t use $wpdb, use wp_query. Not only will your code be leaner and quicker, you’ll avoid issues like this. Unless you’re doing something with custom tables or seriously in-depth SQL, there’s no reason to do direct SQL calls on $wpdb.

So, to answer your question – rewrite it from the ground up using wp_query, see that everything you want to do is documented in the Codex, solve your problems without any hassle, and pat yourself on the back, a job well done.

Leave a Comment