WP REST API – Limit the taxonomy search to the first letter

You can use the rest_names_query filter to handle the custom starts_with REST API parameter, and use the terms_clauses filter to add a custom SQL clause for searching terms having their name starting with the specified letter (e.g. A or a for /wp/v2/names/?starts_with=A): add_filter( ‘rest_names_query’, function( $args, $request ){ if ( ‘/wp/v2/names’ === $request->get_route() && // … Read more

Get child product categories from parent product category in WooCommerce

Edited (1) You will need to use ‘child_of’ from WP_Term_Query available arguments, that will let you to get all child terms for the current product category parent term: // Only on product category archive pages if( is_product_category() ) { $main_term = get_queried_object(); $args_query = array( ‘taxonomy’ => ‘product_cat’, ‘hide_empty’ => false, ‘child_of’ => $main_term->parent ); … Read more

get_the_terms – only top level

Just have a quick test and seems both methods working well. // @Rup’s method $terms = get_the_terms(get_the_ID(), ‘my_taxonomy’); if (!is_wp_error($terms) && !empty($terms)) { foreach ($terms as $term) { // skip if parent > 0 if( $term->parent ) continue; $name = $term->name; $link = add_query_arg(‘fwp_typ’, FWP()->helper->safe_value($term->slug), ‘https://www.freuciv.com/’); echo “<a href=”https://wordpress.stackexchange.com/questions/366690/$link”>$name</a><br />”; } } or $terms = … Read more

How to retrieve category NAME instead of ID in a function with a taxonomy custom field?

You need to get the term object first. //Your meta field $post_custom_title = get_post_meta($post_id,’car_name’,true); //Get the term object by id. change taxonomy_slug to the taxonomy you intend to use $term = get_term_by( ‘id’, $post_custom_title, ‘taxonomy_slug’ ); //Retrive the term name and use it as post title $term_name = $term->name; //call the wp_update_post function setting $term_name … Read more

wp_dropdown_categories and custom taxonomy + custom post type

You can get your code to work the expected way by adding the following three arguments to your $args array which you pass to wp_dropdown_categories(): name — the select name as in <select name=”<here>”>, and you should set it to theme which is your custom taxonomy slug. value_field — the value of the <option>‘s in … Read more