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

How to organize and cache additional data associated with terms?

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

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

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

How does Woocommerce store variation attributes, and how can they be retrieved per-variation? [closed]

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

Why does get_term() require taxonomy? Are term_ids not unique?

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