[wp-trac] [WordPress Trac] #58442: Add parameters for the wp_get_archive function that allows to filter the archive for particular years and months.
WordPress Trac
noreply at wordpress.org
Fri Jun 2 09:00:49 UTC 2023
#58442: Add parameters for the wp_get_archive function that allows to filter the
archive for particular years and months.
-------------------------+-----------------------------
Reporter: sh4lin | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: template |
-------------------------+-----------------------------
Right now there is no way to get the monthly archive for particular year
{{{#!php
<?php
// This is what will separate dates on weekly archive links.
$archive_week_separator = '–';
$sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status
= 'publish'", $parsed_args['post_type'] );
}}}
In order to do that we have to use the filter to change the where clause
as below.
{{{#!php
<?php
if ( ! empty( $parsed_args['in_year'] ) ) {
$year = absint( $parsed_args['in_year'] );
$sql_where .= sprintf( ' AND YEAR(post_date) = %1$d',
$year );
}
return $sql_where;
}}}
I am suggesting here to add optional argument that can filter the months
for a particular year and weeks for particular month likewise.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58442>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list