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
- Could not insert term into the database
- How can I get category ID by category name?
- Multipart/formatted MySQL query problem
- Randomise results from a category page?
- Adding Custom User Profile data based upon Categories
- Only show category to certain user levels without plugin
- Order posts by category name
- How can I make wp_list_categories output li with category-slug as class, for its children?
- Remove word “Category” from WooCommerce product page [closed]
- meta_query on a date range using an array of values
- Output link to category from WP_Query loop of woocommerce products
- Display name of the last child category
- If in category to be inside of a function
- How to exclude posts from a category when using this particular format
- Viewing category pages without the word ‘category’ in URL
- How to provide value for ‘selected’ on wp_dropdown_categories() for ‘multiple’ options
- Need Category RSS Feed that shows all posts
- Nav menu category links not showing
- Making a tourism information website [closed]
- Exclude a category from the_category in the single post page
- How do I see the mysql query generated by get_posts( $args )?
- Post publish directly in all categories except one need pending review
- Display category posts before others category custom query [closed]
- Get Prevous/Next Post Specific Category Without Excludes
- Pagination is not working properly in Product Category/Tag pages
- add_rewrite_endpoint returns 404 on archives
- How to display post type and category links in foreach WordPress code
- Limit authors on specific catogories