Template to list categories in custom taxonomy

I managed to sort this using: <?php $category_ids = get_all_category_ids(); ?> <?php $args = array( ‘orderby’ => ‘slug’, ‘parent’ => 0, ‘taxonomy’ => ‘servicecats’ ); $categories = get_categories( $args ); foreach ( $categories as $category ) { echo ‘<li><img src=””/><a href=”‘ . get_category_link( $category->term_id ) . ‘” rel=”bookmark”>’ . $category->name . ” . ” . … Read more

Get term name without a foreach loop

What about using: echo get_the_term_list( $post->ID, ‘artist-genre’, ‘<li>’, ‘,</li><li>’, ‘</li>’ ); instead, to generate the HTML list? Or simply: the_terms( $post->ID, ‘artist-genre’, ‘<li>’, ‘,</li><li>’, ‘</li>’ ); that’s a wrapper for get_the_term_list(). Also notice that you’re missing the is_wp_error() check, in your code snippet, because wp_get_post_terms() can return the WP_Error object, for an unknown taxonomy. But … Read more

Custom taxonomy pagination

Drop your custom query and go back to the default loop. Never replace the main query on the home page or any kind of archive page with a custom query. Use pre_get_posts to alter the main query variables before the main query runs Your taxonomy archive page should look like this if ( have_posts() ) … Read more

Output unique taxonomy terms of posts inside a loop

Figured it out! $state_tax_args = array( ‘post_type’ => ‘products’, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘product-line’, ‘field’ => ‘slug’, ‘terms’ => $pl_slug // provided at page load ), ), ); $state_tax_query = new WP_Query( $state_tax_args ); // counter to build array $i=0; if ( $state_tax_query->have_posts()) { $state_term_list=”<select class=”form-control” id=”inputStateSelect” … Read more

WordPress implode & wp_insert_post question

The second parameter to wp_set_object_terms() takes an array, integer, or string. (array/int/string) (required) The slug or id of the term (such as category or tag IDs), will replace all existing related terms in this taxonomy. To clear or remove all terms from an object, pass an empty string or NULL. Integers are interpreted as tag … Read more