customization - Avoid showing the same phrase in the loops

I use this multiple loops to show the sold of some wears, so if there are the sold (meta_value=yes) the txt or presentat

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 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 Commented Oct 7, 2019 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 Commented Oct 7, 2019 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 Commented Oct 8, 2019 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 Commented Oct 9, 2019 at 17:55
Add a comment  | 

1 Answer 1

Reset to default 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; ?>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745097757a4611084.html

相关推荐

  • customization - Avoid showing the same phrase in the loops

    I use this multiple loops to show the sold of some wears, so if there are the sold (meta_value=yes) the txt or presentat

    10小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信