Question

Here is what I have:

A custom post type that has a custom meta value added to a post that stores the posts expiry date. When the post passes this expiry date it no longer shows on the site.

This works but I'm using something like this to list the terms for the custom post type:

$termcats = get_terms('dcategory', 'hide_empty=0&orderby=name&pad_counts=1');

I'm showing the count of posts in the listed terms but the problem here is that the count shows all post whether or not if the post has expired. So for example I have one post in the term called test and that post is expired. The above code shows there is one post but when the user click the category they get a blank list.

So I need a way to hook into get_terms() to ignore posts that have expired according to my date field in meta values.

Was it helpful?

Solution

As far as I remember counts for terms are stored in database, so there is nothing to modify when you fetch them - you simply get ready-made numbers.

So you will either need to implement and maintain your special logic for counts completely separately or try to recalculate and modify native counts, see wp_update_term_count_now().

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top