Filtering elements by taxonomy slug

Have a look at the documentation for the_terms(). It requires at least two parameters – the post ID, and the taxonomy name. You’re not giving it either of these (I am of course assuming your taxonomy isn’t called taxonomy-name). However, you’re also using the wrong function for the situation. the_terms() is used to display (i.e. … Read more

How to get if child category of this category is empty?

You’re going to need to loop over the $re_child_terms array. According the docs get_term_children returns an array of term_ids so you will need to loop over the ids, get the terms and save them into a new array if they’re not empty. $re_child_term_ids = get_term_children( $term->term_id, ‘category’ ); $re_child_terms = array(); foreach ( $re_child_terms_ids as … Read more

Get an array of custom taxonomy with posts inside each items

$terms = get_terms( ‘custom_taxonomy’, array( ‘hide_empty’ => false, )); foreach( $terms as $term ) { $args = [ ‘post_type’ => ‘custom_post_type’, ‘post_status’ => ‘publish’, ‘tax_query’ => [ [ ‘taxonomy’ => ‘custom_taxonomy’, ‘field’ => ‘id’, ‘terms’ => $term->term_id, ] ] ]; $posts = new WP_Query( $args ); $result[ $term->term_id ] = $posts->posts; } In result you … Read more

Get Taxonomy name from “registered_taxonomy” hook

$args is an array, not an object: function test( $taxonomy, $object_type, $args ) { echo $args[‘name’]; } add_action( ‘registered_taxonomy’, ‘test’, 10, 3 ); EDIT Using the create_term action: function my_create( $term_id, $tt_id, $taxonomy ){ $term = get_term( $term_id, $taxonomy ); echo $term->name; } add_action( ‘create_term’, ‘my_create’, 10, 3 );

Remove Category When Post Transitions from Status Private To Public And has Specific categories already?

Couple of things: You’re not providing a post to check in in_category(). You’re calling wp_remove_object_terms() on $postID, which hasn’t been set. This code should work: function my_remove_category_on_status_change( $new_status, $old_status, $post ) { if ( $old_status == ‘private’ && $new_status=”publish” && in_category( array( ‘1186’, ‘1208’ ), $post ) ) { wp_remove_object_terms( $post->ID, 1186, ‘category’ ); // … Read more

How to display taxonomy term custom meta (using wp_get_object_terms?)?

If those extra fields are saved on Edit User page you should get them with get_user_meta function: $social_twitter_handle = get_user_meta( $curauth->ID, ‘firm_social_twitter_handle’, true ); If those extra fields are attached to each term you can use get_term_meta function: $firm_terms = wp_get_object_terms( $curauth->ID, ‘firm’ ); if ( ! empty( $firm_terms ) ) { if ( ! … Read more

How to relate a user object to taxonomy term?

The function wp_set_object_terms relates to objects (posts, page, etc). You better use usermeta – update_usermeta. E.g update_usermeta( $user_id, ‘company’, $company_id ); WordPress is built by two major database tables (wp_posts and wp_users) and two (meta tables wp_postmeta and wp_usermeta). It seems that the term tables (wp_terms and others) relates to wp_posts. I dealing with the … Read more

Search Media by taxonomy

To search, use the s option as described in the WP_Query documentation https://codex.wordpress.org/Class_Reference/WP_Query#Search_Parameter Search Parameter Show posts based on a keyword search. s (string) – Search keyword. Show Posts based on a keyword search Display posts that match the search term “keyword”: $query = new WP_Query( array( ‘s’ => ‘keyword’ ) ); Prepending a term … Read more

How to update a taxonomy term for a custom post type with auto incrementing number

/** * Add an auto-incrementing Project ID field to Design feedback posts */ function auto_assign_ids( $post_id, $post, $update ) { // Only assign ID to new design posts if ( $post->post_status == ‘publish’ && $post->post_type == ‘designapprovalsystem’ ) { // get the most recent Project post $project_args = array( ‘numberposts’ => 2, ‘post_type’ => ‘designapprovalsystem’, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)