I'm trying to list taxonomies with posts no older than 45 days, the problem is that it is showing the taxonomy multiple times if there are multiple posts in that taxonomy. So how do I show taxonomies with a new post once only?
Here is the View code:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-post-taxonomy type="subject"]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
and attached is a screenshot of the View query and filter - and the results
The output shown is expected given the View you have created, which loops over *posts* and displays the assigned taxonomies.
You need to come at this from another angle, which is to loop over taxonomy *terms* and display them if they meet your requirements (are assigned to posts published within the past 45 days).
It is not something you can do straight-forwardly with WordPress queries, and so is not something you can do in Toolset without having to involve some custom code.
The steps are
1. create a View which queries the "subject" taxonomy terms
2. in the Loop Output section, output the taxonomy term title (or link), wrapped inside a conditional shortcode which checks a custom function "has_new_posts" for true or false.
3. Write a custom function to test whether there are any new posts for the current term and return a true or false value accordingly.
Writing such custom code falls outside our support policy. I don't know what your level is. If you are capable of doing that yourself, great, if not, let me know and I will try and help you.
This is the function the developer wrote to get this working:
/**
* Find out if there are contemplations for a specific taxonomy
* within specified number of days
*
* @param {int} the number of days
* @param {string} should be 'taxonomy', comes from Toolset
* @param {object} the taxonomy, comes from Toolset
*/
function wpv_conditional_taxonomy_has_newer_posts_than($days, $type, $object) {
$args = array(
'post_type' => 'contemplation',
'tax_query' => array(array(
'taxonomy' => 'subject',
'field' => 'term_id',
'terms' => $object->term_id
)),
'date_query' => array(
'after' => date('Y-m-d', strtotime('-' . $days . ' days'))
)
);
$query = new WP_Query( $args );
return $query->post_count > 0;
}