Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

0

Here is the solution I ended up with. This may help others too. $taxonomy = "product-category"; $args = array( 'taxonomy' => $taxonomy, 'orderby' => 'name', 'order' => 'ASC', 'hierarchical' => true, 'hide_empty' => false, ); $the_query = new WP_Term_Query($args); $categories = $...


0

I'm very late to the party but the error is that you are searching a multidimensional array. You have to specify for the key you are searching for $post_terms = wp_get_object_terms( $post_id, $taxonomy ); if( $post_terms ){ if(($key = array_search($term_id, array_column($post_terms, 'term_id'))) !== false) { unset($post_terms[$key]); } ...


0

In your cases "wp_insert_term" does not save extra custom fields. Please try with below code : foreach ( $this->terms as $term_key=>$term) { // insert new terms in taxonomy wp_insert_term( $term['name'], $this->taxonomy, array( 'slug' => $term['slug'], 'description' => $term['...


0

I created a query, you can use this to find all the categories related to SELECT * FROM wpra_term_relationships INNER JOIN wpra_term_taxonomy ON (wpra_term_taxonomy.term_taxonomy_id=wpra_term_relationships.term_taxonomy_id AND wpra_term_taxonomy.taxonomy='category') INNER JOIN wpra_terms ON (wpra_terms.term_id=wpra_term_taxonomy.term_id ) WHERE object_id='...


0

Now I am able to sort taxonomy terms by term_order using below snippets. But I am still seeking answer for the original question "How to do it using pre_get_terms". function foo_tax_order($orderby, $args){ return 't.term_order'; } add_filter('get_terms_orderby', 'foo_tax_order', 10, 2);


Top 50 recent answers are included