Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save vishalarora91/a2a13e6bb77a32ddf7c16f812784997e to your computer and use it in GitHub Desktop.

Select an option

Save vishalarora91/a2a13e6bb77a32ddf7c16f812784997e to your computer and use it in GitHub Desktop.
// media_coverages = Post Type
$archives_link = wp_get_archives(array('type' => 'yearly', 'post_type' => 'media_coverages', 'format' => 'option', 'echo' => 0));
$archives_link = str_replace('</option>', '</option>, ', $archives_link);
$archives_link = preg_replace('#<option.*?>#si', '', $archives_link);
$archives_link = preg_replace('#<\/option>#si', '', $archives_link);
$archives_links = explode(', ', $archives_link);
foreach($archives_links as $link){
$link = trim($link);
if($link != ''){
echo '<li><a href="/media_coverages/'.$link.'/">'.$link.'</a></li>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment