Separator for multiple terms

If you need just the term names, fetch just the term names: use the field parameter for get_terms(). Build a comma separated list with an and between the last two items with wp_sprintf_l(). // get the term names $term_names = get_terms( ‘department’, array ( ‘fields’ => ‘names’ ) ); // glue the names with comma … Read more

Custom WP_Query breaks default behaviour of viewing right post associated with tax-term!

You second query performs an entirely new query and does not have the terms set. Besides, it’s not as efficient to ‘redo’ the query. Instead, hook into pre_get_posts and change the order there: function change_order_for_events( $query ) { //Check if currenty query is the ‘main query’ and event type taxonomy being viewed if ( $query->is_main_query() … Read more

Display Custom Taxonomy Terns ordered by meta_value

Assuming the position field is filled with numbers to give order: have a look at ksort. <?php $terms = get_terms(‘brands’); // Let’s create our own array and then reorder it $order_terms = array(); foreach( $terms as $term ) { $position = set_up_the_position_meta_here; $order_terms[$position] ='<h2>’.$term->name.'</h2>’; } // now lets reorder the array based on keys (position) … Read more

Manipulating cookie on specific taxonomy archive page

After googling around I found the correct way to do it by using the ‘wp’ hook if (is_tax(‘term-country’)) add_action(‘wp’, ‘my_setcookie’); // my_setcookie() set the cookie on the domain and directory WP is installed on function my_setcookie(){ $path = parse_url(get_option(‘siteurl’), PHP_URL_PATH); $host = parse_url(get_option(‘siteurl’), PHP_URL_HOST); $expiry = strtotime(‘+1 month’); setcookie(‘location’, ‘my_cookie_value_3’, $expiry, $path, $host); }

Taxonomies not appearing in columns on dashboard

Call register_taxonomy() with ‘show_admin_column’ => TRUE and WordPress will create your columns automatically. This parameter was added in version 3.5. You don’t need a custom filter anymore. I have written a small plugin to demonstrate this case: t5-taxonomy-location. This is the registration code: protected function register_taxonomy() { $this->set_labels(); $args = array ( ‘labels’ => $this->labels, … Read more

Is there a way of storing posts and pages under the same hierarchy?

Yes, a custom taxonomy is the best way to achieve this. For a cat breeder site I’ve set a taxonomy for colors (in german: Farbe): register_taxonomy( ‘farbe’, array( ‘post’, ‘page’ ), array( ‘hierarchical’ => false, ‘label’ => ‘Farbe (Fell)’, ‘query_var’ => ‘farbe’, ‘rewrite’ => array(‘slug’ => ‘farbe’) ) ); Note the third parameter array( ‘post’, … Read more

Approach for saving a product attribute values with a custom UI in a woocommerce+dokan set up [closed]

Actually, this ended up being straight forward. Displaying the drop down I used this line to get the list of terms for my pa_condition taxonomy: $attr_condition = get_terms( array( ‘taxonomy’ => ‘pa_condition’, //empty string(”), false, 0 don’t work, and return empty array ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘hide_empty’ => false, //can be 1, ‘1’ … Read more

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