Ok then, I actually was getting the subcats with the wrong method.
in $parent_cat = get_cat_ID( $cat_name );
$cat_name
wasn’t a name but un slug. First mistake.
So I corrected with $parent_cat = get_category_by_slug( $cat_slug );
The final code is :
// Get the parent cat thanks to the page's cat slug
$parent_cat = get_category_by_slug( $cat[1] );
$args = array(
'type' => 'post',
'parent' => $parent_cat->term_id,
'order' => 'DESC'
);
// child cats
$categories = get_categories( $args );
// loop on the child cats to get the sub cats object
foreach ($categories as $key => $value) {
return $value;
}
That’s it.
Related Posts:
- WP_Comment_Query pagination, delving into the unknown
- Sort posts by category name and title
- ajax category filter
- Display posts the match taxonomy term linked from wp_list_categoies?
- WordPress 4.9.5 PHP intermittent warning trim() expects parameter 1 to be string, array given
- Nested query inside Logical operator OR not working in meta_query
- SQL Statement generated by WP_Query not producing expected results
- WP_Query on different site in a multisite setup
- Best practice for multiple queries on page
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- How to user WP_Query to lower the number of queries
- Exclude post on loop by multiple meta key value
- how do i combine keyword search and taxonomy in a WP_query $args array Worpresss [closed]
- How to find out what “Blog pages show at most” is set to [duplicate]
- difference between $wp_the_query and $wp_query? & getting the values properly [duplicate]
- Ignore/Skip default value on orderby menu_order?
- WP_Query order by date in meta_value
- WP_Query pagination not working in admin area
- Custom Field sort not working (WP 3.8.1)
- Sanitizing search data for use with WP_Query
- How to search by a post and a category name on wordpress at the same time?
- What’s the point of the query_vars filter?
- Meta query with order by another custom field
- How can I get an array of all IDs from the current queried object?
- Get Category Archive Template Name Dynamically
- How to limit WP_Query to one result on the loop?
- WP User Query get all authors with last name starting with specific letter
- Query post from all category with same tag on 1 pages
- How to correctly pass values to wpdb->prepare()?
- How to use filter hook “the_posts” with a function that refers to $this?
- Is there a way to include a post multiple times in the same query result?
- WP_Query, pre_get_posts and offset
- Multiple Search Terms WP_Query
- Filtering posts from different categories into different section by doing WP_Query only once
- Suggestions on making this query/code more performant
- Where to put meta Keys
- WP Query Args – Title or Taxonomy Value
- Slow WP_Query with ‘OR’ on meta_query
- How to filter a query by multiple meta keys and order by other meta keys
- Multiple Orderby’s using random order WP_Query
- using pre_get_posts for search results not found
- How to query for all posts that have a particular meta key?
- How can I override one post and make it display content for another post?
- Ajax future single post query doesn’t work when NOT logged in
- Exclude parent with child pages from WP_Query
- Co-authors list of all posts
- Get multiple users with meta value in one query and populate WP_User class
- get_posts always returning the same number of posts = 5
- WP_Query calls all posts?
- WP_Query: apply an SQL function to meta fileld value
- The best way to store variable across different widgets
- Assign a minimum result count for WooCommerce query shortcodes?
- WPQuery calling specific posts problem
- Retrieve data from wordpress db via input and put those result in dropdown
- How to use ‘WP_Query’ or ‘query_posts’ to display content in a descending order
- How to display specific ids of posts using wp_query?
- Filtering by multiple conditions in the loop
- Limit loop to future events
- Echo User Name from User with most comments of today?
- Custom wp_query differs on index page and category page
- Tax_Query using WP_Query not working
- WordPress Queries Not Working?
- How to stack name list in non-alphabetical order?
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- orderby ignored by wp_query
- $wp_query->found_posts not returning correct value
- How to make a post with certain taxonomy term display first before other post with only one query?
- Exception for excluding previously displayed posts in queries
- How do I compare the value of two taxonomies in a wp_query
- display ACF repater field in archive page
- Custom Taxonomy Archive Page to display either ALL listings or only from URL
- query hook parse_tax_query function takes no effect
- Meta query ignores multiple values of the key
- Any way to use FETCH_KEY_PAIR with $wpdb?
- Query by meta key and order by another meta key value
- Filter admin ajax data by url query
- Related posts queries
- Check for not NULL not working in meta query
- Display hierarchical structure of Custom post type in UL LI
- Using a variable within the blog posts array query – posts_per_page as variable
- Single query for multiple categories
- ACF query-pass field value
- Best way to query posts and order by relevancy to query
- Woocommerce WP_Query post__not_in problem
- how to show more than 1 post into three columns query
- tax_query not working for taxonomy slug
- custom query – offset to pagination
- Order Custom Field by Price
- How to Insert data with wp cron
- Get X posts for all post types on Taxonomy term archive
- new WP_Query based on average values of meta fields
- WP_Query breaks pagination
- wpdb LIKE request shows all database data
- Can’t seem to get an else statement correct? [closed]
- query_vars category_name only display one catgory out of multiple categories
- Incorrect posts displayed on category page
- Refresh wp_query with no changes
- SQL query into to WP query
- WordPress WP_Query Search (‘s’) With Multiple Search Terms
- Search results stuck on page 1