Show latest used taxonomy in homepage

You can do it like: $args = array( ‘post_type’ => ‘post_type_name’, // or use default if you use standard ‘numberposts’ => 3, // or you can use 1 if you need only from last post. ‘orderby’ => ‘date’, //by dates to get lastest ‘order’ => ‘DESC’, ); $posts = get_posts($args); $recent_taxonomies = []; foreach ($posts … Read more

Get list of all Topics in use by a custom post type

I think I cracked it actually! Used this snippet: <?php $custom_terms = get_terms(‘topic’); foreach($custom_terms as $custom_term) { wp_reset_query(); $args = array(‘post_type’ => ‘episodes’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘topic’, ‘field’ => ‘slug’, ‘terms’ => $custom_term->slug, ), ), ); $loop = new WP_Query($args); if($loop->have_posts()) { echo ‘<h2>’.$custom_term->name.'</h2>’; } } ?>

The most recent post of custom taxonomy

Because your posts_per_page has a value of -1 means return all matching query. You should update your post_per_page to 1 and specify the order, and orderby parameters. Order the posts by date in descending order. $featured_value_cat_query = new WP_Query( array ( ‘post_type’ => ‘values’, ‘posts_per_page’ => 1, ‘orderby’ => ‘date’, // ‘order’ => ‘DESC’ … … Read more

WP Tax query & order by tax query not working

Here’s an example of working tax_query. The problem I’ve run into with tax_query is forgetting to nest the array (i.e. ‘tax_query’ is array(array(…)). If you don’t do that, it does not work. $args = array( ‘post_type’ => $post_type, ‘posts_per_page’ => -1, //show all posts ‘tax_query’ => array( array( ‘taxonomy’ => $taxonomy, //’field’ => ‘slug’, //’terms’ … Read more