Interrogez tous les messages avec une balise spécifique
-
-
Comment obtenez-vous `$post_tag`.Et votre requêteest lamême que `query_posts` quine devraitpas dutout être utilisée.How are you getting `$post_tag`. And your query is the same as `query_posts` which should not be used at all.
- 0
- 2014-10-15
- Pieter Goosen
-
j'ai unebalise spécifique quej'ai utilisée demanière statiquei have specific tag i used statically
- 0
- 2014-10-15
- Antwan
-
2 réponses
- votes
-
- 2014-10-15
Ilestbeaucoupplusfacile de créer unenouvelle WP_Query que d'essayer d'effacer ou d'écraser l'original.
Si $post_tagest un slug debalise,vouspouvez simplement utiliser:
<?php $the_query = new WP_Query( 'tag='.$post_tag ); if ( $the_query->have_posts() ) { echo '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<li>' . get_the_title() . '</li>'; } echo '</ul>'; } else { // no posts found } /* Restore original Post Data */ wp_reset_postdata();
It's a lot easier to create a new WP_Query than it is to try clearing or overwriting the original.
If $post_tag is a tag slug, you could simply use:
<?php $the_query = new WP_Query( 'tag='.$post_tag ); if ( $the_query->have_posts() ) { echo '<ul>'; while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<li>' . get_the_title() . '</li>'; } echo '</ul>'; } else { // no posts found } /* Restore original Post Data */ wp_reset_postdata();
-
oui $post_tagest letag slagmaisje n'aipas compris quelleest la différencemoyenne dans votre code désoléje suis débutant dans wordpressyes $post_tag is the tag slag but i didn't understand whats the mean difference in your code sorry i m newbie to wordpress
- 0
- 2014-10-15
- Antwan
-
Laprincipale différenceest que votre codetente d'annuler la requête WPprincipale au lieu de simplementen créer unenouvelle.The main difference is that your code attempts to nullify the main WP Query instead of just creating a new one.
- 0
- 2014-10-15
- Courtney Ivey
-
Jene reçois aucunmessagetrouvé. Je suis désolémais y a-t-il une différenceentre letaget letag slug?i m getting no post found i m sorry but is there any dif between tag and tag slug?
- 0
- 2014-10-15
- Antwan
-
Dans la requête,vouspouvez utiliser des slugs ou desidentifiants.In the Query, you can use slugs or ids.
- 0
- 2014-10-15
- Courtney Ivey
-
çamarchemaintenantmaisj'ai ajouté unenouvellebaliseen anglaiset çamarchemaisj'ai desbalisesen arabe donc çane marchepas dessusit's works now but i added new tag in english and it's works but i have tags in arabic so it's dont work on them
- 0
- 2014-10-15
- Antwan
-
- 2016-08-04
Dans votrefunctions.php
/* Display Related Products */ /* ======================== */ if ( ! function_exists( 'display_related_products' ) ) { function display_related_products($post_tag) { ?> <div class="related-products"> <!-- simple WP_Query --> <?php $args = array( 'post_type' => 'product', 'tag' => $post_tag, // Here is where is being filtered by the tag you want 'orderby' => 'id', 'order' => 'ASC' ); $related_products = new WP_Query( $args ); ?> <?php while ( $related_products -> have_posts() ) : $related_products -> the_post(); ?> <a href="<?php the_permalink(); ?>" class="related-product"> <?php if( has_post_thumbnail() ) : ?> <?php the_post_thumbnail( 'full', array( 'class' => 'related-product-img', 'alt' => get_the_title() ) ); ?> <?php endif; ?> </a> <?php endwhile; wp_reset_query(); ?> </div> <?php } }
Appelez den'importe où avec
display_related_products('name-of-the-tag');
In your functions.php
/* Display Related Products */ /* ======================== */ if ( ! function_exists( 'display_related_products' ) ) { function display_related_products($post_tag) { ?> <div class="related-products"> <!-- simple WP_Query --> <?php $args = array( 'post_type' => 'product', 'tag' => $post_tag, // Here is where is being filtered by the tag you want 'orderby' => 'id', 'order' => 'ASC' ); $related_products = new WP_Query( $args ); ?> <?php while ( $related_products -> have_posts() ) : $related_products -> the_post(); ?> <a href="<?php the_permalink(); ?>" class="related-product"> <?php if( has_post_thumbnail() ) : ?> <?php the_post_thumbnail( 'full', array( 'class' => 'related-product-img', 'alt' => get_the_title() ) ); ?> <?php endif; ?> </a> <?php endwhile; wp_reset_query(); ?> </div> <?php } }
Call from anywhere with
display_related_products('name-of-the-tag');
Je dois récupérertous lesmessages avec unebalise spécifique,maisje reçoistous lesmessages à laplace.Ma requêtefonctionne sije publie unepublication avec labalise dontj'aibesoinet queje listetoutes lespublications avec cettebalise,mais lorsqueje publie unepublication avec une autrebalise,elle récupère lanouvellepublication.
Voicima requête: