2011-02-23 3 views
1

Voici mes codes actuels pour obtenir un post populaire de wordpress wp_post table. Comment puis-je exclure ceux dans des catégories telles que 3 ou 4?Comment exclure certaines catégories dans la déclaration SQL

$popularposts = "SELECT ID,post_title FROM {$wpdb->prefix}posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY comment_count DESC LIMIT 0,".$pop_posts; 
$posts = $wpdb->get_results($popularposts); 
+0

Il serait utile de voir le schéma pour wp_post – Dave

Répondre

1

après 'publier' vous ajouter (en supposant que le champ de catégorie est catégorie)

and categorie not in ('3', '4') 

ou, si catégorie est numérique:

and (categorie < 3 or categeorie > 4) 
1

Dugg à travers le web et stackoverflow, presque résolu le problème. Encore faut-il ajouter

ORDER BY comment_count DESC LIMIT 0,".$pop_posts 

quelque part dans le code suivant.

$popularposts = "SELECT * FROM $wpdb->posts 
INNER JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) 
INNER JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) 

WHERE ($wpdb->term_taxonomy.term_id <> 3 
    AND $wpdb->term_taxonomy.term_id <> 4 
    AND $wpdb->term_taxonomy.taxonomy = 'category' 
    AND $wpdb->posts.post_type = 'post' 
    AND $wpdb->posts.post_status = 'publish')"; 
+0

Terminé. ... ET $ wpdb-> posts.post_status = 'publish') ORDER BY $ wpdb-> posts.comment_count DESC LIMIT 0, ". $ Pop_posts; – unigg

Questions connexes