I use this multiple loops to show the sold of some wears, so if there are the sold (meta_value=yes) the txt or presentation must be showing one time in top, and others products in bottom, and if the (meta_value=non) the users see a msg like : No sold available.
in this loop the only problem is the presentation, it showing many time in the top, so pls how can i let it to be showing one time?
Thanks
<?php query_posts('post_type=wear&meta_key=sold&meta_value=yes'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<p>I'd like this presentation to be showing one time if there is the sold</p>
<?php endwhile; ?>
<?php rewind_posts(); ?>
<?php while (have_posts()) : the_post(); ?>
<h1>Yes, there is some sold</h1>
<?php endwhile; ?>
<?php else : ?>
<h1>No sold available</h1>
<?php endif; ?>
I use this multiple loops to show the sold of some wears, so if there are the sold (meta_value=yes) the txt or presentation must be showing one time in top, and others products in bottom, and if the (meta_value=non) the users see a msg like : No sold available.
in this loop the only problem is the presentation, it showing many time in the top, so pls how can i let it to be showing one time?
Thanks
<?php query_posts('post_type=wear&meta_key=sold&meta_value=yes'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<p>I'd like this presentation to be showing one time if there is the sold</p>
<?php endwhile; ?>
<?php rewind_posts(); ?>
<?php while (have_posts()) : the_post(); ?>
<h1>Yes, there is some sold</h1>
<?php endwhile; ?>
<?php else : ?>
<h1>No sold available</h1>
<?php endif; ?>
Share
Improve this question
asked Oct 7, 2019 at 13:23
TaghaBoyTaghaBoy
203 bronze badges
4
|
1 Answer
Reset to default 0This is the solution, And thanks goes to @lai32290
My goal is to have a loop who will search in the clothes store (post_type=wear
), if there are a promotion (meta_key=sold
), if yes (meta_value=yes
) the loop will first show a presentation just one time, and then to post all the articles of Promotion/Sold clothes.
else, if there is no Sold (meta_value=no
), the phrase will be : No sold available
<?php query_posts('post_type=wear&meta_key=sold&meta_value=yes'); ?>
<?php if (have_posts()): ?>
<p>I'd like this presentation to be showing one time if there is the sold</p>
<?php endif; ?>
<?php while (have_posts()) : the_post(); ?>
<h1>Yes, there is some sold</h1>
<?php endwhile; ?>
<?php else : ?>
<h1>No sold available</h1>
<?php endif; ?>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745097757a4611084.html
query_posts
function, this should be avoided, never usequery_posts
. If you want to modify what gets shown on a page, use thepre_get_posts
filter to change what WordPress fetches from the database. Don't create a second new query and discard the first. If you need to create a secondary post loop, useWP_Query
– Tom J Nowell ♦ Commented Oct 7, 2019 at 13:57post_type=wear
), if there are a promotion (meta_key=sold
), if yes (meta_value=yes
) the loop will first show a presentation just one time, and then to post all the articles of Promotion/Sold clothes. else if there is no Sold (meta_value=no
), the phrase will be No sold available This is what i wanna do with that Loop. Thanks – TaghaBoy Commented Oct 7, 2019 at 18:40have_posts
? The solution to your problem isn't WP specific, it's fundamental PHP/programming knowledge of how if/while/for loops work – Tom J Nowell ♦ Commented Oct 8, 2019 at 10:40