How to handle “the_terms” inside loop

To answer your first question What is the difference between those functions get_terms() returns an array of terms objects that belongs to a specific taxonomy get_the_terms() returns an array of terms belonging to a post the_terms() displays an HTML formatting string of term names belonging to a post Because you need your terms not hyperlinked … Read more

How to get Custom Taxonomy ID from the post ID

You can use wp_get_post_terms() which will return all the terms attached to the post, if any. Then, the first term of the array will be able to tell you which taxonomy it belongs to: global $post; $terms = wp_get_post_terms( $post->ID, array( ‘regions’, ‘sections’ ) ); if( ! empty( $terms ) && ! is_wp_error( $terms ) … Read more

Sorting Posts Via Custom Taxonomy Values Using Checkboxes?

Wrap the whole thing within a form and add a submit button in it: <form method=”POST” action=””> <ul class=”filter-sub-dropdown”> … </form> Use term IDs as checkbox values instead of slugs (you’ll save a little server resources): $discipline->slug; > $discipline->term_id Then, in your functions.php file check if that form has been submitted, and change WP’s query … Read more

Custom Taxonomy tree view not showing correctly in backend

Found a solution. It is a WordPress builtin functionality, not a bug. Could be prevented with the ‘wp_terms_checklist_args’ filter. Below an example for use with Custom Post Type ‘product’ and Custom Taxonomy ‘product_category’: add_filter( ‘wp_terms_checklist_args’, ‘checked_not_ontop’, 1, 2 ); function checked_not_ontop( $args, $post_id ) { if ( ‘product’ == get_post_type( $post_id ) && $args[‘taxonomy’] == … Read more

Echo custom taxonomy term name

I managed to solve this and I will post the answer: <?php $args = array(‘number’ => ‘1’,); $terms = get_terms(‘recipes’, $args ); foreach( $terms as $term ){ echo ‘<div class=”title”>’ . $term->name . ‘recipe</div>’; }

List only first-level children of specific custom taxonomy term

First of all you need the term id of hydro term, you can retrive it using get_term_by $hydro = get_term_by(‘slug’, ‘hydro’, ‘product_cat’); After that, you can use the term id as ‘parent’ argument for get_terms $hydro_children = get_terms( ‘product_cat’, array( ‘parent’ => $hydro->term_id ) ); Now you can display a list of this children: if … Read more

Automatically assign taxonomy term if custom meta value exists

You should hook onto the save_post action. add_action( ‘save_post’, ‘add_video_taxonomy’ ); function add_video_taxonomy( $post_id ) { // you should check if the current user can do this, probably against publish_posts // you should also have a nonce check here as well if( get_post_meta( $post_id, ‘video_url’, true ) ) { wp_set_post_terms( $post_id, ‘video’, ‘your_custom_taxonomy_name’, true ); … Read more

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