• Resolved paa1605

    (@paa1605)


    Hey folks,

    I have the following code which returns posts within a set number of days.

    https://pastebin.com/ijt2qmmN

    I found it on a past forum post and it works a treat. However, i need some help in amending the code so that it excludes posts from a certain category. For example, a category with an id of 23.

    Does anyone know what needs to be added to the code in order to achieve this?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Assuming that you have the term_taxonomy_id of the category, this should work:

    $dates = (array)$wpdb->get_results("
         SELECT post_date
         FROM {$tp}posts
         WHERE post_status = 'publish'
         AND post_type = 'post'
         AND ID NOT IN (SELECT object_id FROM {$tp}term_relationships
                        WHERE term_taxonomy_id = 23)
         GROUP BY SUBSTR(post_date, 1, 10)
         ORDER BY post_date DESC
         LIMIT $days
    ");
    Thread Starter paa1605

    (@paa1605)

    Fantastic! Worked perfectly. Thanks ever so much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show posts within X days, help needed in tweaking working code’ is closed to new replies.