jon-sacci
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: sql select posts matching multiple categoriesGreat. Thanks again Michael. It’s a continuous learning curve. =)
Forum: Fixing WordPress
In reply to: sql select posts matching multiple categoriesGeez. Thanks Michael. That makes more sense. Is the
$my_query = null;mandatory or just a good practise? Did I understand correctly, thatwp_reset_query();continues the loop where we left off before our special query?Forum: Fixing WordPress
In reply to: sql select posts matching multiple categoriesFast googling also resulted to the following post.
http://www.asherbond.com/blog/2009/05/21/how-to-select-related-posts-by-tags-and-category-relevance-in-wordpress/Forum: Fixing WordPress
In reply to: sql select posts matching multiple categoriesPardon my spelling. guery is obviously supposed to be query… =P
..and “if it is” should be “if they are”.. Oh well, it’s Monday alright. =DForum: Fixing WordPress
In reply to: sql select posts matching multiple categoriesHi Sinans11,
Don’t forget to check if the post is published. (post_status = publish).
Unless of course you really want 10 posts regardless if it is published or not. =)I use the following guery to get posts under a specific category. I got it by googling, and just added the $cat variable to hold the category id number, instead of defining it in the query. This way I can change the category id dynamically, while using the same query for different categories I want.
$tp = $wpdb->prefix; //-- the table prefix "wp_" etc. $cat = 8; //-- id of the category $cat_query = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND ID IN (Select object_id FROM {$tp}term_relationships, {$tp}terms WHERE {$tp}term_relationships.term_taxonomy_id =$cat) ORDER BY post_date DESC");