Forums

Use wpdb get_col for both post_type AND category (1 post)

  1. smvw
    Member
    Posted 8 months ago #

    I've created an archive listing for custom post types of "insights" listed by year (see below). How do I integrate and add posts of category named "steve" to that same archive listing. To be clear - these posts with a category of "steve" are regular posts and outside of the "insights" custom post type.

    <ul>
    <?php
    $years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_type = 'insights' AND post_status = 'publish' ORDER BY post_date DESC");
    foreach($years as $year) : ?>
    <li><a href="<?php echo '/index.php/insights-list/#'. $year; ?> "><?php echo $year; ?></a></li>
    <?php endforeach; ?>
    </ul>

Reply

You must log in to post.

About this Topic