• Resolved tirion

    (@tirion)


    Hi all,

    I am currently using the below to list posts in a particular category:

    get_results("SELECT guid, post_title, post_excerpt FROM wp_posts, wp_term_relationships WHERE object_id = ID AND term_taxonomy_id = 1")

    It works fine, but I need to be more precise and narrow the results down to certain months using something like…

    get_results("SELECT guid, post_title, post_excerpt FROM wp_posts, wp_term_relationships WHERE object_id = ID AND term_taxonomy_id = 1 AND wp_posts.post_date = ??????????")

    Could anyone advise how to limit the results returned by year, and by month, using the above SELECT query?

    ie, what do I need to add to the SELECT query to limit the results to only posts made in October 2009?

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Better yet, use query_posts (or get_posts or a new WP Query) to get your posts. Look at the Time parameters in the query_posts() article for examples.

    Thread Starter tirion

    (@tirion)

    Thanks for the advice 🙂

    I’ve actually solved this now using a DB query, yay for Google 😀

    $results = $wpdb->get_results("SELECT guid, post_excerpt FROM wp_posts, wp_term_relationships WHERE object_id = ID AND term_taxonomy_id = 1 AND YEAR(post_date) = 2009 AND MONTH(post_date) = 1");

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Date related SQL query, assistance required ;)’ is closed to new replies.