You could try
$slidercategories_array = array(3,5,6,9,10,11,12,23,24,27);
$in = implode( ',', array_map( 'absint', $slidercategories_array ) );
global $wpdb;
$sql = $wpdb->prepare(
'SELECT tt.term_id, MAX(p.post_date) AS max_date FROM ' . $wpdb->term_taxonomy . ' AS tt '
. ' JOIN ' . $wpdb->term_relationships . ' AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id'
. ' LEFT JOIN ' . $wpdb->posts . ' AS p ON (p.ID = tr.object_id AND p.post_type = %s AND p.post_status = %s)'
. ' WHERE tt.term_id IN (' . $in . ') AND tt.taxonomy = %s'
. ' GROUP BY tt.term_id'
. ' ORDER BY max_date DESC'
, 'post', 'publish', 'category' );
$slidercategories_sorted = $wpdb->get_col( $sql );
Related Posts:
- Only one category per post
- How to get permalinks with category base working with sub-categories
- WP 3.9 TinyMCE no longer loads on category description editor
- get_categories hierarchical order like wp_list_categories – with name, slug & link to edit cat
- Change Gutenberg category checkboxes to radios
- Exclude categories from search query
- Why is per_page not working with categories in WP API?
- Programmatically create product category and add thumbnail in woocommerce
- How to order the get_categories result
- List posts by category exclude current post
- How can I calculate the total number of categories at different hierarchy levels?
- How to add a background image to category and display image on category page
- Display only deepest category on a single post?
- How we add new categories by wp_insert_post
- Listing all posts from current category on page
- Show Subcategory Description
- Hide uncategorized products from the shop page
- I want exclude the particular category in sidebar
- wp_list_categories() – adding a div to each li?
- How Can You Exclude Categories From Your RSS Feeds?
- Help with multiple dropdown tags search
- List Posts by Category for a Non-Zero, Non-NULL Custom Field Value?
- How to get category URL with the slug?
- Rename Default Category (Uncategorized) Via a Function
- weekly archive for custom category
- ?cat=-1 Indexed Versions Of Homepage
- How get permalink for the current category or tag?
- using checked function to verify value against an array
- wp_list_categories depth and number
- Show category images on single product page and product overview page
- Category index featured image
- Order categories by most posts
- need to add custom field in more products
- Display specific categories by ID
- Sorting category products not working
- Show category from “Next post” and “Previous post” [edited]
- Custom archive.php: retrieve right post categories?
- Add category only if post has custom taxonomy category
- How to customize categories panel?
- Get posts from 2 different categories
- Show category with link
- Random Featured Image Based on Category
- Failing in_category or has_category in the_content_feed
- Display a list of subcategories a post belongs to
- Display unused categories in dropdown
- Show Pages in Categories
- get_posts ignoring ‘category’ and displaying all posts
- How to change the thumbnail size to a specific category?
- Get paged category link programmatically
- Some of the category description not showing up in category page
- Function to automatically rename the base category permalink
- Add theme-color meta tag to head?
- How to get an array with all categories and corresponding names?
- Is it possible to have a template that works on multiple categories where the link address contains the specific category?
- WordPress Customizer: Dropdown with Category output
- Custom tax_query filter not working for Woocommerce product categories
- display a link to all the categories of current post, including parents
- How do order product categories – on a parent category page – in Woocommerce?
- Need to echo category id in multi-dimensional array
- Display only subcategories of a category and not sub-subcategories
- Use blog as base for tags and categories
- Exclude parent category when getting category posts by slug
- category link not working for a specific slug, works for others
- Shows only one Category in home page
- Update custom category fields front-end
- Exclude the category in WordPress
- How to automatically generate custom menu item from categories?
- Include last post date in get_categories loop
- Categories not posts at the frontpage
- Add Post Categories in Post Tags Field Programmatically
- How do I remove “Uncategorized” from my theme on my posts page?
- Conditional label Woocommerce archive [unsolved]
- How can i change sort category view starting from child then parent, not alphabetically
- Products category search not working
- how tho change number of posts in loop from specific categories
- Showing the category hierarchy as clicked in WordPress, with image and desc
- error in specific category loop
- WordPress category title not update in navigation menu
- problem with filter of custom portfolio categories
- Removing catagory for new blog pages
- Limit post top level categories to one
- Filter custom taxonomy posts via AJAX
- set a parent category in a product woocommerce
- “Next posts” of a category do not call category.php
- Trying to display all posts in a category
- Remove “Category:”
- List post categories that link to a page showing those posts
- Most efficient way to have 1 template for parent, 1 template for child categories?
- If on Category Page add “active” class?
- Custom fields setup when category selected filter subcategories
- Make three menus with three category levels
- Show only one category in main query, issues on tag page
- Bringing Ajax Loading Feature on Category Pages
- Category related -> excerpt, title and thumb in sidebar on article page
- How to have a category not show up in query post with page panigation?
- single category widget with conditional terms
- Remove the current item from a menu
- Show category-ID in custom category-list
- Dynamically Adding Category Specific Content To Specific Category & Subcategory Pages
- How to display all category images for single post in a page?