custom query for both category and pages using global $wpdb;
I have a custom query returning categories, but I also need to return some
pages with a particular post ids. How would I add those? They obviously
have no taxonomy and are page post types.
Below is my query so far:
protected function _getPostByCategory($category) {
global $wpdb;
$result = $wpdb->get_results(" SELECT * FROM $wpdb->posts
LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
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->terms.name = '$category'
AND $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'post'
GROUP BY $wpdb->posts.ID
ORDER BY $wpdb->posts.post_date DESC");
No comments:
Post a Comment