Get Custom posts from specified term.

Posted: December 16, 2011 in WordPress
Tags: ,

$querystr = ”
SELECT *
FROM $wpdb->posts
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
WHERE $wpdb->posts.post_type = ‘message’
AND $wpdb->posts.post_status = ‘publish’
AND $wpdb->term_taxonomy.taxonomy = ‘taxonomy_name’
AND $wpdb->terms.slug = ‘term_name’
ORDER BY $wpdb->posts.post_date DESC
LIMIT 10
“;

$pageposts = $wpdb->get_results($querystr, OBJECT);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s