WordPress.org

Forums

i would to filter the SELECT by just one category id. (2 posts)

  1. stevemail
    Member
    Posted 5 years ago #

    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;
    	}
    }
  2. interactivechris
    Member
    Posted 4 years ago #

    * bump anyone? Have the same problem.....

Topic Closed

This topic has been closed to new replies.

About this Topic