Tell us what you are trying to do? A dropdown select to filter by year
Is there any documentation that you are following? No
Is there a similar example that we can see? No
Nigel,
To my question previously answered by you today, we decided to go to another approach regarding the WordPress Archives filter by year and month widget.
We wish to implement a filter that filters content by year, which is a select. This will be a Toolset custom field.
We believe the easiest approach is to use custom taxonomy in the filter section.
To avoid duplication of work, In the post above you suggested adding a save_post hook that sets the category year according to the saved date.
But would it possible to no use the saved date (which i think you are talking about the "modified" date), instead use the original published date, would this be possible? If so, is there any snippet that does this?
You can use the following code snippet to automatically assign a year taxonomy term to posts when they are saved/updated based upon the original publication date.
You'll need to edit the slug of the taxonomy (in my example the taxonomy has a slug of 'published-year').
You will also need to create the terms beforehand, i.e. create the year terms 2019, 2018, 2017 etc. in the WP admin.
function tssupp_assign_year($post_id, $post, $update) {
$tax_slug = 'published-year';
// does post already have year taxonomy set?
$year_term = get_the_terms($post, $tax_slug);
if (!$year_term) {
// get the year of the published date and set term
$year = substr($post->post_date, 0, 4);
$year_term = get_term_by('name', $year, $tax_slug);
wp_set_post_terms($post_id, array($year_term->term_id), $tax_slug);
}
}
add_action('save_post', 'tssupp_assign_year', 10, 3);