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 get parent and child sub category (Taxonomy) order to display
- select posts from sql except posts from specific category
- How to query by subcategory and, if there are fewer than 10 posts in that subcategory, fill out with posts from parent category
- How to make query loop block dynamic
- Unable to browser posts in categories
- How to add meta description, keywords, custom title to a category template
- Custom menu with categories and tags
- User level categories
- Exclude category from drop down list form
- How do I export the headlines of all the blog posts in a single category?
- Add class to current post in query_post
- Load the last post of a category
- create function to call category name and slug
- How to Show or Hidden Categories on page in WordPress?
- separate posts to have (kind of) 2 blogs?
- 3.1 post formats and specific categories/custom taxonomies
- how can we bring category metabox to Media Library/Upload New Media Page
- How can I display a list of categories of my posts
- create relationship between posts from one category and posts from another category
- Posts made to category don’t show up (do show up on frontpage)
- sidebar troubles, taxonomy trouble
- Code for Category, Tags, Archive URLs
- Display all posts from selected category
- WordPress Custom Query: Combining Two Functions
- WP E-Commerce WPEC 3.8 Sort Categories
- Is there any better/faster code than this ? It shows the categories that an author had ever posted in
- Exclude the category of the current post
- How do I list only children of a specific category in a drop-down?
- Link posts together (relative, not grouped)
- can I ‘combine’ categories as a menu item?