• Hi, in Functions.php, i have this function to display recent posts (all). But i would to filter the SELECT by just one category id. Putting something like : (AND) $wpdb.posts.category_id=16 (having posts under the #16 category) this not list anything…

    Anyone knows how (and where) must i filter the SELECT by getting just one category ?

    This is the function where i would to add a filter by (one) category…

    # Displays a list of recent posts
    function dp_recent_posts($num, $pre='<li>', $suf='</li>', $excerpt=true) {
    	global $wpdb;
    	$querystr = "SELECT $wpdb->posts.post_title, $wpdb->posts.ID, $wpdb->posts.post_content FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ORDER BY $wpdb->posts.post_date DESC LIMIT $num";
    	$myposts = $wpdb->get_results($querystr, OBJECT);
    	foreach($myposts as $post) {
    		echo $pre;
    		?><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title ?></a><?php
    		if ($excerpt) {
    			?><p><?php echo dp_clean($post->post_content, 120); ?>...</p><?php
    		}
    		echo $suf;
    	}
    }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘i would to filter the SELECT by just one category id.’ is closed to new replies.