Reverse Woocommerce product order

Viewed 138

First time posting here so don't mind the noobness. I am a web and Wordpress designer, don't know php but usually can get by -- this is probably an easy fix (might not even require php) but it's really got me stumped.

Something I changed (I believe the product order from Customize page) messed up the product order on this website I'm working on's homepage. No matter what settings I try, it still comes up in the same order, with the bumper sticker as the first choice when we want it to be shown LAST.

The order does seem to work on the "shop" page, just not the front page.

As a last resort, I'm thinking there must be a way to at least reverse the php query to show them listed backwards... there must be a better way though

Heres the code anyway


                    <div class="content--offset">


                        <?php

                        $args = array( 'post_type' => 'product');
                        $loop = new WP_Query( $args );

                        while ( $loop->have_posts() ) : $loop->the_post(); ?>
                        <?php $price = get_post_meta( get_the_ID(), '_price', true ); ?>
                        <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $loop->post->ID ), 'single-post-thumbnail' );?>

                                <div class="content__item product" style="--aspect-ratio: 5/5;">
                                        <div class="content__item-imgwrap">
                                            <a href="<?php echo get_permalink( $loop->post->ID ) ?>"><h5><?php the_title(); ?><br><span><?php echo wc_price( $price ); ?></span></h5></a>
                                            <div class="content__item-img" style="background-image: url('<?php  echo $image[0]; ?>');"></div></div>
                                        <a href="product.html"><h5 class="content__item-title "></h5>
                                    </a>
                                </div>

                        <?php endwhile; wp_reset_query();?>


                    </div>

Any help much apprec!! Thanks!

1 Answers

This would probably be better on https://wordpress.stackexchange.com/. Just for future :)

You could try adding 'order' => 'DESC' as a param in your $args array?

Like so:

$args = array(
  'post_type' => 'product',
  'order' => 'DESC'
);

Also see PHP's array_reverse method if you'd like to reverse the $loop array of products after you query it.

Related