[resolved] Display a specific category using SQL data (3 posts)

  1. _OMEGA_
    Posted 6 years ago #

    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).

  2. MichaelH
    Posted 6 years ago #

    //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

  3. _OMEGA_
    Posted 6 years ago #

    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 :D

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.