0

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; ?>
  • 1
    Hello! I'm not sure what you mean by "the sold" can you rephrase that or explain what you mean? Also I notice you used the query_posts function, this should be avoided, never use query_posts. If you want to modify what gets shown on a page, use the pre_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, use WP_Query – Tom J Nowell Oct 7 at 13:57
  • Hello, The Sold is the promotion of the price of certain clothes. 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 This is what i wanna do with that Loop. Thanks – TaghaBoy Oct 7 at 18:40
  • 1
    If that's the case why have. post loop at all? Why not just check have_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 Oct 8 at 10:40
  • I'm not really expert in the WP coding also in PHP, can you please recreate that code with the best practice of coding? Thanks a lot. – TaghaBoy Oct 9 at 17:55
0

This 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; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.