• Hi, i need to retrieve certain data from the post – and showed one category’s post data first (preference) in the coupon’s list and then other categories post data second in the list.

    I meant to say that suppose first 6 coupons are first preference, then it will be shown first then the rest. And then goes the pagination. Therefore as, i found on the internet – i try to use the 2 LOOPS for (one category & rest of the category respectively.

    my website is https://www.coupon.mn

    But the problem is even i click the second page, it is showing the first page data, not the rest of the data. Thanx in advance. I try to find answers through the internet no success, plz help.

    I used the following code; plz help me what i am missing.

    <?php
                $args = array();
                $args['post_type'] = 'coupons';
                $args['cat'] = 20;
                $query1 = new WP_Query($args);      
    
                while($query1->have_posts() ) : $query1->the_post();
                $thumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
                $discount = get_post_meta($post->ID, '_single_discount', true);
                $date = get_post_meta($post->ID, '_single_date', true);
                $code = get_post_meta($post->ID, '_single_code', true);
                $url = get_post_meta($post->ID, '_single_url', true);
                $daysleft = round( ($date-time()) / 24 / 60 / 60);
            ?>
            <div class="coupon">
                <?php if($thumb != '') { ?>
                    <div class="coupon-top">
                        <figure>
                            <a href="<?php the_permalink();?>"><img src="<?php echo aq_resize($thumb, 300, 200, true); ?>" alt="<?php the_title();?>"></a>
                        </figure>
                        <div class="coupon-title">
                            <a href="<?php the_permalink();?>"><?php truncate_title(15);?></a>
                        </div>
                    </div>
                <?php } ?>
                <div class="coupon-bottom">
                    <div class="coupon-offer">
                        <?php echo  substr($discount, 0, 15);?>
                    </div>
                    <div class="coupon-date">
                        <?php
                            if($date == '')_e('Х?чинтэй', 'Couponize');
                            else if($daysleft <= 0) _e('Дууссан', 'Couponize');
                            else echo sprintf( _n('%d day left.', '%d Хоног ?лдсэн.', $daysleft, 'Couponize'), $daysleft );
                        ?>
                    </div>
                </div>
            </div>
            <?php endwhile;  wp_reset_postdata();?>
    
            <?php
                $args = array( 'category__not_in' => array(20));
                $args['post_type'] = 'coupons';
                $query2 = new WP_Query($args);
    
                while($query2->have_posts() ) : $query2->the_post();
                $thumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
                $discount = get_post_meta($post->ID, '_single_discount', true);
                $date = get_post_meta($post->ID, '_single_date', true);
                $code = get_post_meta($post->ID, '_single_code', true);
                $url = get_post_meta($post->ID, '_single_url', true);
                $daysleft = round( ($date-time()) / 24 / 60 / 60);
            ?>
            <div class="coupon">
                <?php if($thumb != '') { ?>
                    <div class="coupon-top">
                        <figure>
                            <a href="<?php the_permalink();?>"><img src="<?php echo aq_resize($thumb, 300, 200, true); ?>" alt="<?php the_title();?>"></a>
                        </figure>
                        <div class="coupon-title">
                            <a href="<?php the_permalink();?>"><?php truncate_title(15);?></a>
                        </div>
                    </div>
                <?php } ?>
                <div class="coupon-bottom">
                    <div class="coupon-offer">
                        <?php echo  substr($discount, 0, 15);?>
                    </div>
                    <div class="coupon-date">
                        <?php
                            if($date == '')_e('Х?чинтэй', 'Couponize');
                            else if($daysleft <= 0) _e('Дууссан', 'Couponize');
                            else echo sprintf( _n('%d day left.', '%d Хоног ?лдсэн.', $daysleft, 'Couponize'), $daysleft );
                        ?>
                    </div>
                </div>
            </div>
            <?php endwhile; wp_reset_postdata();?>
  • The topic ‘How to show the post's data of some category first, and then the rest?’ is closed to new replies.