• My sidebar’s archive list is by year. How do I exclude the year of drafts (year 0) from the php or SQL? Here’s my code:

    <ul>
    <?php
    $years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts ORDER BY post_date DESC");
    foreach($years as $year) : ?>
    <li><a href="<?php echo get_year_link($year); ?> "><?php echo $year; ?></a></li>
    <?php endforeach; ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • $years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date DESC");

    Thread Starter dblume

    (@dblume)

    Many thanks, Kafkaesqui. I got my code from the codex in the 1.5 days. I’ve updated the query to your submission.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How To Exclude Drafts from Archive’ is closed to new replies.