wp_set_object_terms() Fails to Set Terms
I don’t have a solution, but there’s a ticket #20541 on Make WordPress Core. Apparently a call to switch_to_blog() would not repopulate $wp_taxomies, which these taxonomies rely on.
I don’t have a solution, but there’s a ticket #20541 on Make WordPress Core. Apparently a call to switch_to_blog() would not repopulate $wp_taxomies, which these taxonomies rely on.
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 );
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
I’d say your third option is the way to go. Incidentally, why did you roll your own static cache in taxonomy_image_plugin_get_associations() instead of using the built-in WP_Cache API for that? Is there a reason wp_cache_get wouldn’t work here? Seems like using the WP object cache would optimize better when people do have caching plugins turned … Read more
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
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
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 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
Attributes are stored on wp_term_relationships. Ex: +————–+——————-+——————-+ | object_id | term_taxonomy_id | term_taxonomy_id | +————–+——————-+——————-+ | 91 | 48 | 0 | +————–+——————-+——————-+ Product 91 has an attribute 48
I’ve logged a ticket against this with trac: http://core.trac.wordpress.org/ticket/20536 However, it turns out that for the time being it IS necessary, as WordPress currently (since 2.x) has a bug that DOES associate two terms with the same name to the same term_id! So it IS possible (though incorrect) for a single term to be associated … Read more