get a specific taxonomy term name

Use get_term() to get the name, slug, or description: $term = get_term( 1, ‘taxonomy_slug’ ); // Name echo $term->name; // Link echo get_term_link(1, ‘taxonomy_slug’); // OR echo get_term_link( $term );

Using pre_get_posts to set posts per page, how do I?

You’re almost there mate. Try this though. <?php add_action(‘pre_get_posts’, ‘filter_press_tax’); function filter_press_tax( $query ){ if( $query->is_tax(‘press’) && $query->has_term(‘press’)): $query->set(‘posts_per_page’, 5); return; endif; } ?> You can use any conditional tag or any argument that can be passed to WP_Query to test your condition or set a new value via pre_get_posts. Also try $query->get(‘taxonomy’) / $query->get(‘term’). … Read more

get term by id without taxonomy

Yes, but you need you make your own SQL query. A modified version of WP’s get_term(): function &get_term_by_id_only($term, $output = OBJECT, $filter=”raw”) { global $wpdb; $null = null; if ( empty($term) ) { $error = new WP_Error(‘invalid_term’, __(‘Empty Term’)); return $error; } if ( is_object($term) && empty($term->filter) ) { wp_cache_add($term->term_id, $term, ‘my_custom_queries’); $_term = $term; … Read more

Automatically Assign Parent Terms When A Child Term is Selected

Hooking into save_post action. add_action(‘save_post’, ‘assign_parent_terms’, 10, 2); function assign_parent_terms($post_id, $post){ if($post->post_type != ‘product’) return $post_id; // get all assigned terms $terms = wp_get_post_terms($post_id, ‘product_cat’ ); foreach($terms as $term){ while($term->parent != 0 && !has_term( $term->parent, ‘product_cat’, $post )){ // move upward until we get to 0 level terms wp_set_post_terms($post_id, array($term->parent), ‘product_cat’, true); $term = get_term($term->parent, … Read more

What is wp_insert_term “alias_of” arg for?

In the Code Reference it says: ‘alias_of’ (string) Slug of the term to make this term an alias of. Default empty string. Accepts a term slug. This makes a term an alias of another term. Using your example this is how you would use it: wp_insert_term( ‘e’, ‘tax’, array( ‘alias_of’ => ‘a’ ) ); This … Read more

tax_query in get_posts() not working?

tax_query takes an array of tax query arguments arrays (it takes an array of arrays) but you are using only single array. The correct code is as following. $uposts = get_posts( array( ‘post_type’ => ‘product’, ‘numberposts’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => $cat->taxonomy, ‘field’ => ‘slug’, ‘terms’ => array($cat->slug), ‘operator’ => ‘IN’, ) … Read more

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