Comment exclure une taxonomie personnalisée de la boucle de publication
-
-
Des articles contenant destermes dans cettetaxonomie,oufaites-vous référence à untermeparticulier de votretaxonomiepersonnalisée?** Exemple: ** Simataxonomieestfruitet quej'ai deuxtermes,pommeet orange,est-ce queje voudraisexcluretous lesmessages qui contiennent desfruits ou simplement ceux qui contiennent despommes?Any posts that have any terms in that taxonomy, or are you referring to a particular term of your custom taxonomy? **Example:** If my taxonomy is fruit and i have two terms, apple and orange, would i want to exclude all posts that have fruit, or just those that have apples?
- 5
- 2011-03-16
- t31os
-
pour étendre @t31os Q:post_tag,category,link_category,etc. sonttoutes destaxonomies _builtin.Ainsi,même si vous appelez lesbalises depublication des «termes»,il s'agittoujours d'unetaxonomie (non hiérarchique)et aumême «niveau» que lataxonomie de «catégorie» (hiérarchique).to extend @t31os Q: post_tag, category, link_category, etc. are all _builtin taxonomies. So, even if you'd call post tags "terms", it's still only a taxonomy (non-hierarchical) and on the same "level" as "category" (hierarchical) taxonomy.
- 0
- 2011-03-16
- kaiser
-
Pour continuer l'exemple @t31os:j'essaie d'excluretous lesmessages qui sont dans lataxonomiefruit (qu'ils soient dans «pommes»,«poires» ou «oranges»).To continue @t31os example: I am trying to exclude all posts that are in the taxonomy fruit (regardless of whether they're in 'apples', 'pears' or 'oranges').
- 0
- 2011-03-17
- Thomas
-
6 réponses
- votes
-
- 2017-04-17
Vous voudrez utiliser l'opérateur
NOT EXISTS
en passant le slug detaxonomie,quiindique à la requête dene pasinclure une catégorie choisie dans votretaxonomiepersonnalisée dans laboucle.Pourexcluretous les articles de lataxonomie "fruit" (quel que soit letype defruit),voici l'extrait:
$args = array( 'post_type' => 'post', 'tax_query' => array( array( 'taxonomy' => 'fruit', 'operator' => 'NOT EXISTS' ) ) ); $query = new WP_Query( $args );
You would want to use the
NOT EXISTS
operator along with passing the taxonomy slug, which tells the query not to include any of a chosen category from your custom taxonomy inside the loop.To exclude all posts that are in the taxonomy "fruit" (regardless of fruit kind), here is the snippet:
$args = array( 'post_type' => 'post', 'tax_query' => array( array( 'taxonomy' => 'fruit', 'operator' => 'NOT EXISTS' ) ) ); $query = new WP_Query( $args );
-
Cela semble êtreplusefficace que de dire «PAS DANS» XXnombre de «termes».Cette liste determespourrait atteindre unetailleimportante,maiselle devrait couvrirtous lestermesportant lenom de cettetaxonomie.This looks like it should be more efficient than saying `NOT IN` XX number of `terms`. That list of terms could grow to a large size, but this should cover all terms with that taxonomy's name.
- 2
- 2017-05-12
- italiansoda
-
Bien que ce soit la réponse à la question du PO (votéepour),laplupart d'entrenous veulentprobablementexclure unterme ou unensemble determes spécifique.Pour cela,vous voulez [cette réponse] (https://wordpress.stackexchange.com/a/12616/10388).While this is the answer to the OP's question (upvoted), most of us probably want to exclude a specific term or set of terms. For that, you want [this answer](https://wordpress.stackexchange.com/a/12616/10388).
- 0
- 2019-08-02
- rinogo
-
- 2011-03-21
La solution à ceproblèmen'estpas vraimentmédiatisée,maiselle devrait l'être.
Vouspouvezeffectuer les opérations suivantes:
$args['tax_query'] = array( array( 'taxonomy' => 'category', 'terms' => array('cat', 'dog'), 'field' => 'slug', 'operator' => 'NOT IN', ), ); query_posts($args);
L'argument de l'opérateurpeutprendre d'autrestermes,mais le code ci-dessusindiqueessentiellement d'obtenirtous lesmessages de lataxonomie «catégorie» quine contiennentpas lestermes «chat» ou «chien».
The solution to this isn't really that publicised, but it should be.
You can do the following:
$args['tax_query'] = array( array( 'taxonomy' => 'category', 'terms' => array('cat', 'dog'), 'field' => 'slug', 'operator' => 'NOT IN', ), ); query_posts($args);
The operator argument can take other terms, but the above code is basically saying get all posts from the taxonomy 'category' that don't have the terms 'cat' or 'dog'.
-
Intelligent.Mais alorsj'auraistoujoursbesoin de saisirmanuellement chaqueterme de cettetaxonomie,n'est-cepas?Clever. But then I'd still need to manually enter every term in that taxonomy, correct?
- 0
- 2011-03-21
- Thomas
-
Jene te suispas désolé.Dans letableau determes,vous définissez les valeurs determe que vous souhaitezexclure de votre requêteen boucle.Si vous vouliez qu'elles soient dynamiques,vouspouvezpeut-être ajouter une valeurmétapersonnalisée à chaquepublication,puis vérifier la valeur de cette cléméta dans votre requêteet la définir de cettefaçon si c'est ce que vous voulez dire.I'm not following you sorry. In the terms array, you define the term values that you want to exclude from your loop query. If you wanted them to be dynamic, you can perhaps add a custom meta value to each post and then check for the value of that meta key in your query and set it that way if that's what you mean.
- 0
- 2011-03-21
- Dwayne Charrington
-
Ah.Je vois ce quetu veux dire,mais c'est vraimentencombrant.Ah. I see what you mean, but that's really cumbersome.
- 0
- 2011-03-27
- Thomas
-
Jen'aipas vraiment cherché,maisil doit sûrement y avoir unplugin quifait ce que vous demandez alors?I haven't really looked, but there surely must be a plugin that does what you're asking then?
- 0
- 2011-03-27
- Dwayne Charrington
-
- 2011-09-29
Voici commentprocéderpour lestypes d'articlespersonnaliséset lestaxonomiespersonnalisées:
$happening = new WP_Query( array( 'post_type' => 'news', // only query News post type 'tax_query' => array( array( 'taxonomy' => 'news-cat', 'field' => 'slug', 'terms' => 'media', // exclude items media items in the news-cat custom taxonomy 'operator' => 'NOT IN') ), ) );
Cela aparfaitementfonctionnépourexclure lataxonomiepersonnalisée dutype depublicationpersonnalisé. Je voulaisjuste ajouter le code de laboucle de requêtepourterminer l'extrait de code: while ($the_query-> have_posts ()): $the_query->the_post ();
Here's how to do it for custom post types and custom taxonomies:
$happening = new WP_Query( array( 'post_type' => 'news', // only query News post type 'tax_query' => array( array( 'taxonomy' => 'news-cat', 'field' => 'slug', 'terms' => 'media', // exclude items media items in the news-cat custom taxonomy 'operator' => 'NOT IN') ), ) );
This worked perfectly to exclude custom taxonomy from custom post type.. Just wanted to add the query loop code to finish off the snippet: while ( $the_query->have_posts() ) : $the_query->the_post();
-
- 2012-04-27
J'aifait ce qui suitpourexclure des articles d'un certainterme detaxonomie:
$argos = array( 'tax_query' => array ( array( 'taxonomy' => 'topics', // My Custom Taxonomy 'terms' => 'college', // My Taxonomy Term that I wanted to exclude 'field' => 'slug', // Whether I am passing term Slug or term ID 'operator' => 'NOT IN', // Selection operator - use IN to include, NOT IN to exclude ), ), 'post_type'=>'page', // Post type I want to show, can be a custom post type too 'posts_per_page' => -1, 'orderby' => 'title', 'order'=>'ASC', 'post_parent' =>$post->ID // show child posts or pages of current page/post ); $query = new WP_Query( $args );
I did the following to exclude posts from a certain taxonomy term:
$argos = array( 'tax_query' => array ( array( 'taxonomy' => 'topics', // My Custom Taxonomy 'terms' => 'college', // My Taxonomy Term that I wanted to exclude 'field' => 'slug', // Whether I am passing term Slug or term ID 'operator' => 'NOT IN', // Selection operator - use IN to include, NOT IN to exclude ), ), 'post_type'=>'page', // Post type I want to show, can be a custom post type too 'posts_per_page' => -1, 'orderby' => 'title', 'order'=>'ASC', 'post_parent' =>$post->ID // show child posts or pages of current page/post ); $query = new WP_Query( $args );
-
- 2017-01-21
query_posts( array( 'post_type' => 'listings', 'tax_query' => array( array( 'taxonomy' => 'status', 'field' => 'slug', 'terms' => 'sold', 'operator' => 'NOT IN' ), ) ) );
Ce codeexclut status=> vendu àpartir depost_type=> annonces
query_posts( array( 'post_type' => 'listings', 'tax_query' => array( array( 'taxonomy' => 'status', 'field' => 'slug', 'terms' => 'sold', 'operator' => 'NOT IN' ), ) ) );
This code excludes status => sold from post_type => listings
-
- 2011-03-16
J'utilise leplugin WordPress "RYO 'Category Visibility'" qui semblefonctionnerplutôtbien.
Vouspouvez décider sur unepage d'administration quelles catégories sont visibles ouexclues de différentes zones.
http://ryowebsite.com/wp-plugins/category-visibility/
-Adam
I use the "RYO ‘Category Visibility’ WordPress Plugin" that seems to work pretty well.
You can decide on an admin page what categories are visible or excluded from various areas.
http://ryowebsite.com/wp-plugins/category-visibility/
-Adam
-
Ilme semble que devoirinstaller unplugin supplémentairepour cefaireestexagéré.Jepréfèregardermes dépendances auminimumet il doit sûrement y avoir unmoyenpour que cela sefasseen boucle.It seems to me that having to install an additional plugin to do this is over the top. I'd rather keep my dependencies to a minimum and surely there must be a way for this to be done in the loop.
- 4
- 2011-03-17
- Thomas
Existe-t-il unmoyen simple oufacile d'excluretous lesmessages d'unetaxonomiepersonnalisée dans laboucle?J'ai cherché hautet bas,et ni SE,SO ou Googlene semblent avoir de réponse claire.
Je sais que celapeut êtrefait via une requête WPDB,mais cela semble être une corde énormepour sauterpour quelque chose qui devrait être assez simple.