Support » Fixing WordPress » Display a specific category using SQL data

  • Resolved _OMEGA_


    Hi guys, I’m writing here because I need you help.
    I have written this code in my template:

    $sql_data = “
    SELECT *
    FROM $wpdb->posts
    WHERE post_date_gmt > “.(time()-strtotime(‘-2 weeks’)).” AND post_type = ‘post’
    ORDER BY…….”;

    I want to modify this code to fit my idea but I’ve searched in the Codex and on the forum but I haven’t found a solution.

    I’d like to define a date, for example the posted articles in the last 2 weeks and only the articles in the Category (50).

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php
    //based on Austin Matzko's code from wp-hackers email list
      function filter_where($where = '') {
        //posts in the last 14 days
        $where .= " AND post_date > '" . date('Y-m-d', strtotime('-14 days')) . "'";
        return $where;
    add_filter('posts_where', 'filter_where');
    query_posts($query_string . '&cat=50');

    query_posts->Time Parameters

    I’ve found and tried this:

    SELECT DISTINCT ID, post_title
    FROM $wpdb->posts as p
    INNER JOIN $wpdb->term_relationships AS tr ON (p.ID = tr.object_id AND
    tr.term_taxonomy_id IN (44) )
    INNER JOIN $wpdb->term_taxonomy AS tt ON
    (tr.term_taxonomy_id = tt.term_taxonomy_id AND taxonomy = ‘category’);

    and it do what I need!
    Finally thx 😀

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display a specific category using SQL data’ is closed to new replies.