The reason it’s only getting parents is this part:
parent=0
This queries categories that don’t have a parent, so you only get the top level. Remove it and you’ll get all categories:
get_terms('category','hide_empty=false')
That being said, you’d be better off using wp_dropdown_categories()
. That way you will get the proper ordering and indentation of child categories:
<label for="<?php echo $this->get_field_id( 'link' ); ?>">
<?php _e( 'دسته بندی' ); ?>
</label>
<?php
wp_dropdown_categories(
[
'id' => $this->get_field_id( 'link' ),
'name' => $this->get_field_name( 'link' ),
'class' => 'widefat',
'selected' => $instance['link'],
]
);
?>
Related Posts:
- wp_list_categories: order by term order?
- Difference between get_category, get_term_by and get_categories
- get_terms from registered taxonomies not working
- Display custom taxonomy on single post
- Group child category IDs based on their parent category
- Getting all categories even with no products under it?
- Add HTML to Term Description
- How to create a array that contains all of the children slugs of a specific parent category
- List posts by their custom taxonomy term, with a condition
- I can get posts in all categories. But I want to get the custom post type I created
- Is there any WordPress way to get all categories for some selected posts?
- get_terms vs. get_categories: does it matter?
- Woocommerce get category image full size
- Control term order on a per-post basis
- Fixing category count
- Why does WordPress combine a term with the same name in the wp_terms table?
- Exclude posts that only have the ‘Uncategorized’ category [duplicate]
- Elegant way to add parent categories?
- Exclude Child Terms From Parent Posts
- same taxonomy for several post types: how to hide empty in a specific post type?
- How to sort terms with diacritical signs?
- get_terms(); show private posts when logged in
- Get category ID after wp_insert_term
- Send an email when custom post type category is changed
- How to order get_term_children output by alphabetic order
- get_post_terms not working as expected
- Update term count using a callback function
- wp_update_term not creating new unique slug
- Display Categories Assigned to a WooCommerce Product
- Does WordPress Offer a Way to Find All of the Categories that Don’t Have Children?
- Removed slug from CPT, now How/where do I hook the filter to the taxonomy term archive pages link?
- Action hooks returning old category instead of new category
- Wp set post terms not work
- Display empty taxonomy terms with get_terms()
- Get the Term List – Ordering
- Reduce / optimize calling of wp_get_object_terms() when generating permalinks
- Problems with function on function.php
- How to order and count get_terms by specific post type?
- Get those terms with a specific meta key value
- get_term_by “name” not working with & in name
- I want to loop through Woocommerce Product Catogories and show them in dropdown
- setting taxonomy term to bulk posts using ids
- display taxonomy slug from term ID
- Modify automatically generation of slug when term is created
- Custom Post Type Archive Page Filtering
- Does get_terms() use any sort of caching on its query?
- 404 on term taxonomy archive pagination only with some terms
- Clone Terms of one taxonomy to another
- Get random out from get_terms()
- Categories order with get_terms_args not working in 4.7
- Get posts from specific taxonomy term
- Getting category URL with hyphens, not spaces
- How to get a post’s associated taxonomies and terms in wp api v2
- Get all terms linked to a post and include those who not connected from get_terms and sort
- single_term_title() running before get_the_title() [closed]
- Get terms within a custom taxonomy
- How to get the $meta_type given the $object_id
- How to Link to Most Recent Custom Post of Same Term
- Parent category / child category posts
- $args for get_terms() to return ORDER BY FIELDS
- Custom term templates
- Showing HTML if Post is In Certain Taxonomy Term
- INSERTING Data into table with placeholders
- Get Custom Post Child Term
- WordPress custom taxonomy
- Retrieve Custom Taxonomies with Description and Slug
- Taxonomy Drop Down with hierarchical view using $terms
- How to check if a term is parent to another?
- Combining these queries? (Same taxonomy term + same category as post)
- Create Terms on taxonomy by text field
- Customizing the wordpress tag-cloud output
- Add properties to term object
- get_object_term_cache duplicate terms after update to wordpress 6
- Sort categories by custom field in WordPress admin
- How to display custom taxonomy term specific post?
- Why does term get inserted twice when using dynamic slug?
- Replace deprecated get_category_children code with get_terms
- Create category after theme setup and modify the default one
- Cannot get to work tax_query array for terms
- Update term_id to new value wherever it exists, to combine the two.
- wp_set_post_terms struggle :(
- Add subcategories posts to the counts column at the admin’s categories list
- How to show only tagged CPT categories / taxonomies for a custom post type?
- Get category of a taxonomy for a queries object in a loop
- Order terms by creation date
- Unable to retrieve any child terms using get_terms
- WordPress using get_term to retreive slug not working as expected
- Get terms parent ID for conditional IF statement
- Get count for all terms inside a parent term
- Display List of Categories Within a Custom Taxonomy
- add links to list of post terms
- List Terms by category
- When I Use function wp_insert_term() function it gives me Invalid taxonomy object
- How to add a new child category via an SQL statement?
- Why is my post categories not displaying?
- Use get variable when rewritten url in wordpress
- Attempting to filter posts using get_terms
- Issue on Listing Sub Product Categories In Woocommerce
- How to solve/debug get_terms suddenly showing no results?
- How to display First level child terms of current term’s parent taxonomy?