Depending on use case scenario you might need to write some custom code or a tiny plugin to achieve this. If you want to filter the posts in admin dashboard post list then you can use following code snipped to jump start
<?php
if (is_admin()){
//this hook will create a new filter on the admin area for the specified post type
add_action( 'restrict_manage_posts', function(){
global $wpdb, $table_prefix;
$post_type = (isset($_GET['post_type'])) ? quote_smart($_GET['post_type'], true) : 'post';
//only add filter to post type you want
if ($post_type == 'YOUR_POST_TYPE_HERE'){
$values = array();
$query_years = $wpdb->get_results("SELECT year(post_date) as year from ".$table_prefix."posts
where post_type="".$post_type.""
group by year(post_date)
order by post_date");
foreach ($query_years as &$data){
$values[$data->year] = $data->year;
}
?>
<select name="admin_filter_year">
<option value="">All years</option>
<?php
$current_v = isset($_GET['admin_filter_year'])? $_GET['admin_filter_year'] : '';
foreach ($values as $label => $value) {
printf(
'<option value="%s"%s>%s</option>',
$value,
$value == $current_v? ' selected="selected"':'',
$label
);
}
?>
</select>
<?php
}
});
//this hook will alter the main query according to the user's selection of the custom filter we created above:
add_filter( 'parse_query', function($query){
global $pagenow;
$post_type = (isset($_GET['post_type'])) ? quote_smart($_GET['post_type'], true) : 'post';
if ($post_type == 'YOUR_POST_TYPE_HERE' && $pagenow=='edit.php' && isset($_GET['admin_filter_year']) && !empty($_GET['admin_filter_year'])) {
$query->query_vars['year'] = $_GET['admin_filter_year'];
}
});
}
If you want to do it in front end then my suggestion will be a custom query
and ajax
. For this scenario I’m for not be able to provide an example as it’s a bit complex. As you have to use elementor in front end you can develop a widget for this too!