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

How do I access a single term from a post?

It’s a little bit hard to be sure, what are you asking exactly, but… Let me try to answer… So somewhere in single.php you’re getting terms for current post using this code: $terms = wp_get_post_terms($post->ID, ‘mytax’, array(“fields” => “all”)); and you want to get the ID of first term from that list? If so, you … Read more

Formating the_terms() function output

While you can specify separators and such in the_terms() arguments, it assumes that you actually want links. You can discard unwanted HTML by using filter: add_filter(‘the_terms’, ‘no_terms_links’, 10, 2); function no_terms_links($term_list, $taxonomy) { if (‘type’ == $taxonomy) return wp_filter_nohtml_kses($term_list); return $term_list; } Or just use deeper get_the_terms() function and iterate through its return to build … Read more