Update wordpress post terms programatically
Please add taxonomy name in wp_set_post_terms function. wp_set_post_terms( $id, $prod_cats, ‘product_cat’ ); Please refer wpcodex wp_set_post_terms
Please add taxonomy name in wp_set_post_terms function. wp_set_post_terms( $id, $prod_cats, ‘product_cat’ ); Please refer wpcodex wp_set_post_terms
Ok, so I think I’ve got something for you! As you know, I’ve had the same issue, and when I was looping through each taxonomy I found that I was generating between 25-35 queries, which is crazy! So I decided to have a go at some MySQL on the term relationships table to see if … Read more
Although the hooks are passing you the ID of the changed object in the parameter $object_id, you aren’t using it and are calling get_the_ID instead which will give you the ID of the current loop item. Try changing your uses of $post_id to $object_id instead.
I was working on someone else WP installation so I can get the info of WP Database to show Products information in a side-page. I’ve noticed that they have a plugin installed (Taxonomy order) that always return the terms posts in the same orden. Sorry for the confusion!
Not sure from which version, but count argument not used anymore. Just checked WP_Term_Query class and found nothing related to count argument in get_terms() method, but you can still find it in constructor of this class. To return terms count only, you need to set count for fields argument. get_terms( array( ‘parent’ => $categoryId, ‘taxonomy’ … Read more
Here’s an alternative based on a single taxonomy.php file. In summary, call a function at the beginning of taxonomy.php. The function evaluates the taxonomy url and identifies which custom taxonomy (if any) applies. It then gets ALL the terms for that taxonomy (not just the one in the url), and then gets ALL the posts … Read more
It is always ‘save_post’ (or ‘wp_insert_post’ immediately after this). In $_POST[‘tax_input’] you will find all the terms for all taxonomies associated with the current post. Example: ‘tax_input’ => array ( ‘location’ => array ( 0 => ‘0’, ), ), To change the terms you have to call wp_set_post_terms( $post_ID, $tags, $taxonomy ); manually, just changing … Read more
Don’t need get_term_children() at all. Just loop through get_the_terms() to get what’s needed. global $post; $brands_id = get_term_by(‘slug’, ‘brands’, ‘product_cat’); $terms = get_the_terms($post->ID, ‘product_cat’); foreach ($terms as $term) { if($term->parent === $brands_id->term_id) { echo $term->name; break; } }
I think I have cracked this, thanks to a Redditor’s help. The advice was, effectively: start with 3 and 4 (“Use get_posts() to build an array of post ids that match conditions 3 and 4”) then refine by 1 and 2 (“then drop that array into the object_ids argument for your get_terms() query”)… Like… // … Read more
I had an idea of combining the first code with this solution that lists posts from a specifik taxomony: <?php $terms = get_terms(‘productcategories’); foreach ($terms as $term) { $wpq = array ( ‘taxonomy’=>’productcategories’, ‘term’=>$term->slug, ‘order’=>’asc’, ‘orderby’=>’title’); $query = new WP_Query ($wpq); echo “$term->name:<br />”; ?> <?php if ($query->have_posts() ) : while ($query->have_posts() ) : $query->the_post(); … Read more