How to display custom taxonomy in multiple columns?
How to display custom taxonomy in multiple columns?
How to display custom taxonomy in multiple columns?
There’s not a real efficient way to do this. You’ll either have to make 3 queries or create your own SQL query and use global $wpdb;. For simplicity purposes I’ve went with a 3 query approach. If we know the slugs or IDs we can pass them to our tax query. Since the example code … Read more
It sounds like you’re looking for the get_term_link() function. Your code will look something like this: <?php $catid = get_sub_field(‘selected_category’); $term_link = get_term_link( intval( $catid ), ‘product_cat’ ); ?> <h4><a href=”https://wordpress.stackexchange.com/questions/95584/<?php echo esc_url( $term_link ); ?>”><?php the_sub_field(‘title’); ?></a></h4> As you can see, get_term_link() takes two argument, the term and taxonomy. If you’re saving the term … Read more
Just some code to get started. This will get you all the IDs for job_listings that are assigned to term 4 in your taxonomy. <?php $posts = get_posts( array( ‘posts_per_page’ => -1, ‘fields’ => ‘ids’, ‘post_type’ => ‘job_listing’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘agency’, ‘field’ => ‘term_id’, ‘terms’ => 4 ) ) ) ); … Read more
As discussed in chat and as @Rarst already told you, there’s no default WordPress way to accomplish Archive of multiple taxonomies and all their terms In fact there’s no way to accomplish Archive of single taxonomy and all its terms in WordPress. Simply because WordPress doesn’t do that – without custom SQL queries. But there’re … Read more
Based on this answer, here is my function to get all your terms in an array : function get_term_ancestors($post_id, $taxonomy){ // Declare the array where we are going to store the terms $ancestors = array(); // start from the current term $parent = array_shift(get_the_terms($post_id,$taxonomy)); // climb up the hierarchy until we reach a term with … Read more
Update 1 As @Florian pointed out, we do not need to use the wp_list_pluck function, we could simply add the ‘fields’ => ‘ids’ to the WP_Query to retrieve the list of ids: $producers = new WP_Query( array( ‘fields’ => ‘ids’, ‘post_type’ => ‘producers’, ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘region’, ‘field’ => … Read more
Thinking aloud here… $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘term_id’, ‘terms’ => array( 202, 203 ), ‘include_children’ => 1, ), array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘term_id’, ‘terms’ => array( 100 ), ‘include_children’ => false, ) ), ), ); … Read more
I have a solution, but it’s a really ugly one. I’d love to hear a better one, but I’m not sure it’s possible. WP_Query::get_posts() calls parse_tax_query() twice: first near the start, then again just before getting the SQL from it. There’s no single hook that lets me intercept and adjust the value of $tax_query in … Read more
WP defaults to showing normal native Posts in archives. It won’t automagically pick up which post types you want in your archive. You will have to adjust main query for it to explain that to it, with something like: add_action( ‘pre_get_posts’, function ( WP_Query $query ) { if ( $query->is_main_query() && $query->is_tax( ‘department’ ) ) … Read more