Created
December 9, 2021 06:08
-
-
Save santanup789/3fe7e1cbb6aa84d42db307f791b90848 to your computer and use it in GitHub Desktop.
List down the available archive options like year month etc in a select dropdown or in normal div format with active link to redirect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--<select name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;"> | |
<option value=""><?php //esc_attr( _e( 'Select Month', 'textdomain' ) ); ?></option> --> | |
<?php wp_get_archives( array( | |
'post_type' => 'afr-news', | |
'type' => 'yearly', // monthly | |
'format' => 'custom', // option | |
'before' => '<div class="sub-item">', | |
'after' => '</div>', | |
'show_post_count' => 0 // 1 | |
) ); | |
?> | |
<!--</select>--> | |
//Below code is for the wp_query to fetch the post from queried year. | |
<?php | |
$year = get_query_var('year'); | |
$args = array( | |
'post_type' => 'post', //write slug of post type | |
'posts_per_page' => 5, | |
'paged' => $paged, | |
'order' => 'DESC', | |
'orderby' => 'date', | |
'date_query' => array( | |
array('year' => $year), | |
), | |
); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment