Send an email when custom post type category is changed

Use the hooks added_term_relationship and deleted_term_relationships. These only fire when the relationship changes, as opposed to set_object_terms which always fires: function wpse_181090_object_terms_updated( $object_id ) { static $did = array(); // This function might fire multiple times for the same object, ensure it only runs once if ( ! isset( $did[ $object_id ] ) ) { … Read more

Prevent Selected Terms Rising to the Top

This bugs me too. It is very confusing, so I thought I’d look into it. That meta box is created in “wp-admin/includes/meta-boxes.php” on line ~399. It uses wp_terms_checklist. The problem codes seems to be this (it is one in source): <?php wp_terms_checklist( $post->ID, array( ‘taxonomy’ => $taxonomy, ‘popular_cats’ => $popular_ids ) ) ?> That leaves … Read more

Sort get_users by custom field

By using this you can get your result in ascending order for sort_order custom field $users = get_users( array( ‘meta_key’=> ‘sort_order’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’ ) ); foreach( $users as $user ) { echo ‘<h4>’ . $user_info-> user_firstname . ‘ ‘ . $user_info-> user_lastname . ‘</h4>’; }

wp_insert_term auto unique name

EDIT PART DEUX OR PART DEUX – The Dirty Sequal, The Term Saga Continues… Before anyone read this section, I will urge you to read everything I explained in ORIGINAL ANSWER. wp_insert_term() does not allow duplicate term names in non hierarchical taxonomies or in hierarchical taxonomies within the same hierarchy. From comments to my answer, … Read more

Not Able to Insert Taxonomy Term Using wp_insert_post()

Few points come to mind: There is a typo in “post_type” => “‘eyeglasses” (extra single quote). It should be: “post_type” => “eyeglasses”. Try putting the $term instead of array( $term ): “tax_input” => array( “models” => $term ) Also, is it models or model? e.g. “tax_input” => array( “model” => $term ) tax_input requires assign_terms … Read more

get_terms() returns an empty array

get_terms returns an array of objects. You cannot echo an array, if you do, you will just get Array(). What you can do is print_r($array) or var_dump($array) or echo json_encode($array) to see the data it contains. Otherwise, to get single elements, e.g. the name, from the objects, you need to pass $tax_terms through a foreach … Read more