Rechercher des messages par ID de taxonomie personnalisée
4 réponses
- votes
-
- 2011-10-07
La raisonpour laquelle celane fonctionnepasest que 'tax_query' doit être untableau detableaux (déroutant,je sais).
... 'tax_query' => array( array( 'taxonomy' => 'build-type', ...
C'est ainsi que vouspouvez regrouperplusieurs règles différentes.
The reason this isn't working is because 'tax_query' needs to be an array of arrays (confusing, I know).
... 'tax_query' => array( array( 'taxonomy' => 'build-type', ...
It is that way so you can group a few different rules together.
-
Nice one Drew.Cela l'a résolu.Publié le scriptfinal sur Github https://gist.github.com/1275191Nice one Drew. That solved it. Posted the final script on Github https://gist.github.com/1275191
- 0
- 2011-10-10
- mattberridge
-
À votre santé!J'aipassé une heure dubudget des clients à résoudre ceproblèmemineur :)Cheers! Spent hour from customers budget resolving this minor issue :)
- 0
- 2017-01-09
- Tom
-
- 2011-10-19
Drew avait raison,
tax-query
doit être untableau detableauxLa solutionfinaleest:
// gets the ID from a custom field to show posts on a specific page $buildType = get_post_meta($post->ID, 'build_type_id', true); // run query query_posts(array( 'post_type' => 'portfolio', 'showposts' => -1, 'tax_query' => array( array( 'taxonomy' => 'build-type', 'terms' => $buildType, 'field' => 'term_id', ) ), 'orderby' => 'title', 'order' => 'ASC' ) );
Surgithubici:
https://gist.github.com/1275191
Merci!
Drew was right,
tax-query
needs to be an array of arraysThe final solution is:
// gets the ID from a custom field to show posts on a specific page $buildType = get_post_meta($post->ID, 'build_type_id', true); // run query query_posts(array( 'post_type' => 'portfolio', 'showposts' => -1, 'tax_query' => array( array( 'taxonomy' => 'build-type', 'terms' => $buildType, 'field' => 'term_id', ) ), 'orderby' => 'title', 'order' => 'ASC' ) );
On github here:
https://gist.github.com/1275191
Thanks!
-
Refuserma réponseet accepter la vôtrefait vraimentmal à l'homme ...me faitmal au cœur.Si quelqu'un abesoin demoi,je serai dans le salon.Unaccepting my answer and accepting your own really hurts man... hurts me in my heart. If anybody needs me, I'll be in the lounge.
- 0
- 2011-10-19
- Drew Gourley
-
Hah désolémec.Je suisnouveau danstout cela,je ne savaispas que vousne pouviez avoir qu'une seule réponse.Je vais le re-marquerpour que vouspuissiez vous aventurer hors du salonHah sorry dude. I'm new to all this, didn't realise you could only have one answer. I will re-mark it so you can venture back out of the lounge
- 0
- 2011-10-20
- mattberridge
-
Hahamec c'estbon,je plaisantaisjuste - Si vous voulez accepter une réponse,c'esttotalement autorisé,mais assurez-vous de voterpourma réponse afin quej'obtienne aumoins unpoint d'amour.Haha man it's alright, I was just joking around - If you want to self-accept an answer its totally allowed, but be sure to Upvote my answer so I at least get some point love.
- 0
- 2011-10-20
- Drew Gourley
-
- 2011-10-07
Vous devez créer untableau danstax_query où vouspouvez également sélectionner des opérateurs. Parexemple,unprint_r detax_query devrait ressembler à ceci.
Array ( [relation] => AND [0] => Array ( [taxonomy] => build-type [terms] => Array ( [0] => term1 [1] => term2blabla ) [field] => slug [operator] => IN ) [1] => Array ( [taxonomy] => another-taxonomie [terms] => Array ( [0] => term1 [1] => term2 ) [field] => slug [operator] => IN ) )
Bien sûr,vouspouvez changer le champpourid,maisj'aitoujours utilisé des slugspour simplifier les choses. Comme vouspouvez le voir,vouspouvezinterrogerplusieurstaxonomies comme celles-ci.
You need to create an array inside tax_query where you can also select operators. For example a print_r of tax_query should look like these.
Array ( [relation] => AND [0] => Array ( [taxonomy] => build-type [terms] => Array ( [0] => term1 [1] => term2blabla ) [field] => slug [operator] => IN ) [1] => Array ( [taxonomy] => another-taxonomie [terms] => Array ( [0] => term1 [1] => term2 ) [field] => slug [operator] => IN ) )
Of course you can change the field for id but i always used slugs to keep it simpler. As you can see you can query multiple taxonomies like these.
-
J'ai untype depublicationpersonnalisé appelé
portfolio
et unetaxonomiepersonnalisée appeléebuild-type
(faisant office de catégories)J'essaie d'interroger lespublications de
portfolio
par ID debuild-type
,parexempletous les articles duportfolio dans "Hôtels" (id=4pour cettetaxonomie)Actuellement,il appelle tous les
portfolio
postset pas seulement ceux avec l'IDbuild-type
Pour
'field' => 'term_id'
dois-je utiliserterm_id
,tag_ID
,id
ou autre chose?Est-ce que quelqu'un sait commentfairefonctionner cela?
Merci d'avance!