0

Good day! I am building this Blog Archive page and it requires filtering of posts by months, using dropdown. Any idea how to do this?

enter image description here

<?php
       // what goes here

      printf('<option value=".%s">%s</option>', `what_here`, `what_here`);
 ?>
0

1 Answer 1

0

You can try to use wp_get_archives() function.
Example from this link:

<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( 'type' => 'monthly', 'format' => 'option', 'show_post_count' => 1 ) ); ?>
</select>
1
  • Thanks! I'll make use of this. Another question though, when you want to load the blogs on the same page, it requires AJAX, correct? Currently the code given above directs to a new page.
    – ddd
    May 12, 2021 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.