Add Taxonomy Description with wp_set_post_terms

You can’t use wp_set_post_terms() to set the term description, but you can use wp_insert_term() to create the term and set the description (plus other details), and then pass the term ID to wp_set_post_terms(). Working example for one term: $taxonomy = ‘category’; $term_name=”Foo Bar”; // First we create the term (if it doesn’t already exist). if … Read more

Can anybody provide me with a function to generate slugs?

This post provides a function, but it cannot handle non-latin characters. That’s because URLs can’t have non-latin/ASCII characters. Browsers might show non-latin characters to you, but it’s just a user interface feature. For example, if you visit this Wiktionary URL: https://en.wiktionary.org/wiki/わかもの#Japanese, you browser URL encodes the japanese characters to get the real URL: https://en.wiktionary.org/wiki/%E3%82%8F%E3%81%8B%E3%82%82%E3%81%AE#Japanese then … Read more

Leveled – Terms foreach

Why not use wp_list_categories( ‘taxonomy=section’ ) ? It’ll do all the nesting & hard work for you! If you want more control over the HTML output, implement a custom walker.

wp_set_object_terms not working inside loop

You can pass an array of terms to wp_set_object_terms, there is no need for the for each: $genres= array(‘action’, ‘comedy’, ‘horror’); $ret = wp_set_object_terms( $postId, $genres, ‘genres’);

A mandatory agreement form to access another page?

I would use a shortcode for this. Wrap the content you want behind the “terms_required” shortcode, if the user hasn’t agreed to the terms, show them the form. The form would submit to a custom rewrite rule (url endpoint) that validates the form and sets a cookie if everything checks out. Let’s start by wrapping … Read more

wp_set_post_terms is assigning only the last of several terms to a post

You need send a fourth argument to the function: wp_set_post_terms($post_id, $actor_term_id, ‘actor’, true); Each time the function executes, you’re replacing any existing terms. The fourth argument specifies that you wish to append them. https://codex.wordpress.org/Function_Reference/wp_set_post_terms

Display custom taxonomy attached to the post on post single page

You can get every Taxonomy by $categories = get_the_terms( get_the_id(), $taxonomy-slug ); if ( is_array( $categories ) ) { foreach ( $categories as $category ) { echo ‘<a href=”‘ . get_term_link( $category->term_id ) . ‘” title=”‘ . sprintf( __( “View all posts in %s” ), $category->name ) . ‘” ‘ . ‘>’ . $category->name.'</a> ‘; … Read more