Skip to content

Instantly share code, notes, and snippets.

@santanup789
Created December 9, 2021 06:08
Show Gist options
  • Save santanup789/3fe7e1cbb6aa84d42db307f791b90848 to your computer and use it in GitHub Desktop.
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
<!--<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