You could use the get_tax_sql() function introduced in WP 3.1:
$tax_query = array(
array(
'taxonomy' => 'category',
'terms' => array( 4, 6, 7, 9 ),
'operator' => 'NOT IN'
)
);
$clauses = get_tax_sql( $tax_query, $wpdb->posts, 'ID' );
...
"SELECT ID, post_date, post_date_gmt, comment_status, comment_count
FROM $wpdb->posts {$clauses['join']}
WHERE post_status="publish"
AND post_type="post"
{$clauses['where']}
"
...
(not tested)
Related Posts:
- Custom Query to search through categories
- How Do I Merge Categories With phpMyAdmin
- How to get related tags based on a category?
- How Do I Delete WordPress Posts Older Than 400 Days, From A WordPress Category
- how to get postmeta info based on multiple categories?
- is_category() in pre_get_posts strange error
- Rearranging posts based on categories
- How to create 450 categories in wp
- How to query all posts of a specific category, and any other category combination
- is_category in pre_get_posts results in php notices
- Query the Loop without breaking it
- How to Check if a Child Category is Being Queried
- Category archive page – loop through posts of certain tag (with pagination) – pre_get_posts
- If newest post of category is newest post in general, skip first post of category
- Include posts from feature category in pre_get_posts
- Accessing WordPress MySQL Database via Data Connection in Visual Studio 2010 using C#
- How to display posts under a specific subcategory of a given category
- get_the_category and echo out link to child-most/deepest category
- Change the category of all posts in it
- How to run select query of post with category and tags for API?
- query in category.php repeats itself
- Display posts separated by Category in Author’s page
- Category param redirect to post type archive
- SQL to migrate post types to taxonomy
- Show popular post by category code
- How to get latest posts from each category in regular order
- Drop posts from categories in MySql
- category pagination got broken suddenly
- WordPress Post # of # filtered by category slug
- How to query categories with Advanced Custom Fields?
- Where and when does WordPress invoke routes
- Can Categories be used to hack a Multisite-like setup w/ a single MySql db?
- And/Or Category Query
- Exclude category from query
- Overriding default calendar to show posts from a category
- How to list all categories and their IDs using SQL query?
- function query_posts disabling current_page_menu class
- Using in ‘category_name’ in ‘$query->set();’?
- custom query for both category and pages using global $wpdb;
- Get categories of queried posts
- Query from multiple category (and)
- How to display posts from specific category using get_option function?
- SQL query to get posts from multiple categories but not in a category
- Conditional category query breaking?
- WordPress: Using the category slug get the category ID using mysql query
- How to add categories using mysql
- How to filter post from categories only if the posts appears in one of them, not the other?
- Category name for all posts getting assigned to a single random post
- Show Posts via cat+cat in URL that are in both Categories doesn’t work
- List of post categories only associated to another custom taxonomy
- how tho change number of posts in loop from specific categories
- How do I merge WooCommerce categories with the same name?
- Get category from slug list
- Bulk Change WordPress category Slug
- Issue with WordPress category search
- Querying posts from two different categories while looping inside another loop
- Too many categories drastically slow down my website
- How to get posts from many categories using WP_Query
- Is it possible to query the result of a query?
- show posts found in multiple categories via category_name query string?
- Match two taxonomies to display a specific content
- Category slug in in loop always the same?
- display certain category on custom template page
- Detecting top parent category fails on home page
- How to use Greek characters/letters in a query?
- Displaying posts by year
- wordpress category.php query for featured news item, broken pagination and repeating posts
- finding out the top 5 source ( source is a custom taxonomy ), in a given category
- How to make that all posts with a category belong also to another
- How to show posts of a specific category
- How to display only 3 main categories, separated by commas, since they are marked in the post?
- How do I create a way for users to assign categories to a post from the frontend?
- Give specific category its own permalink structure
- Add category to custom post type automatically, using category slug
- Connecting WordPress gallery to custom categories (taxonomy)
- Multi-site or categories?
- View the latest created categories
- If statement within PHP echo
- Problem displaying one post from each category
- get_posts and multiple categories
- How do I get rid of “category” from my URL structure?
- Only one post is showing on category page, why?
- how to get full category path including parent and subcategories
- WordPress get from single.php back to the right category page
- WordPress link to post links to category (loop)
- Display all product tags associated with a specific product category
- How replace individual elements in the RSS feed with a single string
- what file I need to create to work date archive links?
- Assigning certain pages or posts to use the template of the parent page or category
- How to get posts using category slug in ClassiPress?
- Assign author to category and not only posts
- How to fetch common posts from two feeds?
- Change post category within pre_get_posts
- Subcategory Page 404ing
- displaying one category on one page
- Ajax Category add doesn’t update the list table custom column
- Question About Messing With Category Pages and Descriptions
- List Terms by category
- List products from current category
- Replace category titles inside RSS feed