Trouble adding custom featured image for custom taxonomy TERMS
Trouble adding custom featured image for custom taxonomy TERMS
Trouble adding custom featured image for custom taxonomy TERMS
Assuming the position field is filled with numbers to give order: have a look at ksort. <?php $terms = get_terms(‘brands’); // Let’s create our own array and then reorder it $order_terms = array(); foreach( $terms as $term ) { $position = set_up_the_position_meta_here; $order_terms[$position] ='<h2>’.$term->name.'</h2>’; } // now lets reorder the array based on keys (position) … Read more
The problem is the use of the php function list. If successful, wp_insert_term returns something of the form: array(2) { [“term_id”]=> int(307) [“term_taxonomy_id”]=> int(325) } You can’t use list with this as list only works for numerical arrays. Instead try extract instead: extract($result); echo “<p>The term <i>{$term_name}</i> under the <i>{$term_taxonomy}</i> taxonomy has been added into … Read more
Where are you calling this code? You need to add it to one of the init hooks. If I add that to either a plugin or theme init, then it adds just fine for me, with the $slug typo corrected as Mike pointed out. echo ‘<p>Debug: Loaded functions.php</p>’; function yourtheme_init() { echo ‘<p>Debug: called yourtheme_init</p>’; … Read more
I think you are running into trouble with these lines in wp_update_term(): 3287 // Merge old and new args with new args overwriting old ones. 3288 $args = array_merge($term, $args); https://core.trac.wordpress.org/browser/tags/4.1.1/src/wp-includes/taxonomy.php#L3287 The array passed in gets merged with the data already in the DB. Set your slug explicitly: $nname=”my new name”; wp_update_term( 10, ‘artists’, array( … Read more
I guess this function is what you are looking for -> get_ancestors()
I don’t know which line that error refers to but this code works correctly if everything falls into place exactly right. But there are actually several ways this could go wrong. For example, if get_query_var(‘author_name’) is not set you get an error on this line: $used_terms=list_author_used_terms($user->ID); If a problem occurs here: $terms = wp_get_object_terms( $p->ID, … Read more
I know I am not answering exactly your question but in my opinion it is best to do it manually without messing with rewrite rules and filters. That way you keep also the default URL structure for terms templates, other plugins etc. $terms = get_the_terms( $post->ID, ‘industry’); if($terms && !is_wp_error($terms)){ echo ‘<ul>’; foreach ( $terms … Read more
This is my best approach: Store the values in an array during the while loop, and then using array_count_values php function, you obtain the desired output. It is untested, but I think it should work: if ( $query->have_posts() ) { //in this variable, declared as an array, we will store the values $products_array = array(); … Read more
Inserting boolean term meta values When we add non-existent term meta with e.g. add_term_meta( 123, ‘test’, true ); then we are actually running the following insert : $wpdb->insert( ‘wp_termmeta’, array( ‘term_id’ => 123, ‘meta_key’ => ‘test’, ‘meta_value’ => true ) ); within the general add_metadata() function. Now wpdb::insert() is actually a wrapper for wpdb::_insert_replace_helper() that … Read more