Get terms of posts with category with sql

Here’s the solution: global $wpdb; $wpdb->get_results( $wpdb->prepare( “SELECT tags.*, COUNT(tags_rel.object_id) as posts_count FROM {$wpdb->prefix}terms tags INNER JOIN {$wpdb->prefix}term_taxonomy tags_tax ON (tags_tax.term_id = tags.term_id) INNER JOIN {$wpdb->prefix}term_relationships tags_rel ON (tags_tax.term_taxonomy_id = tags_rel.term_taxonomy_id) INNER JOIN {$wpdb->prefix}posts posts ON (tags_rel.object_id = posts.ID) INNER JOIN {$wpdb->prefix}term_relationships cats_rel ON (posts.ID = cats_rel.object_id) INNER JOIN {$wpdb->prefix}term_taxonomy cats_tax ON (cats_rel.term_taxonomy_id = cats_tax.term_taxonomy_id) … Read more

WordPress Custom Query

<?php $querystr = ” SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = ‘date_field’ AND wpostmeta.meta_value=”03/11/2010″ AND wposts.post_status=”publish” AND wposts.post_type=”post” ORDER BY wposts.post_date DESC “; $pageposts = $wpdb->get_results($querystr, OBJECT); ?> Then you would access $pageposts as an object

Return ID of authors who have at least one post

Instead of a JOIN, you can use a IN with a subquery, to prevent duplicate results because of the join: SELECT ID, display_name FROM wp_users WHERE ID IN (SELECT post_author FROM wp_posts) This will not look at capabilities. If you also want that you can add them like a join, but move the meta_key clause … Read more

WordPress will not operate correctly

You probably messed up with the config on the DB I would like the dump of the config table please, that way i can see the paths to your wp install (i had a similar problem which i solved by manually correcting the fields in DB) EDIT Run this sql query and let me know … Read more