Jump to content


Replying to How To Change Product Order In Custom Category Template


Post Options

  or Cancel


Topic Summary

verityweb

Posted 24 July 2014 - 05:28 AM

View PostRonald, on 23 July 2014 - 01:26 PM, said:

Hi,

the query you have set up is not selecting Exchange products specifically, so it's not the way to do this.

If the setup in the Exchange Settings isn't working, than I think that is the issue to focus on,

And you can always use the following code (and change to suit your needs) to change the Exchange products order:

function my_products_order( $query ) {
	
	 $post_type = $query->get( 'post_type' );
	
	 if ( !is_admin() && $post_type == 'it_exchange_prod' ) {
			 $query->set( 'order', 'asc' );
	 }
	
}
add_filter( 'pre_get_posts' , 'my_products_order' );

you should add this to at the end of your child theme's functions.php file, but before a closing ?>, if any

Ronald

Duh! How could I forget something so simple? :)

Thanks!

ks

Ronald

Posted 23 July 2014 - 01:26 PM

Hi,

the query you have set up is not selecting Exchange products specifically, so it's not the way to do this.

If the setup in the Exchange Settings isn't working, than I think that is the issue to focus on,

And you can always use the following code (and change to suit your needs) to change the Exchange products order:

function my_products_order( $query ) {
		
		$post_type = $query->get( 'post_type' );
		
		if ( !is_admin() && $post_type == 'it_exchange_prod' ) {
				$query->set( 'order', 'asc' );
		}
		
}
add_filter( 'pre_get_posts' , 'my_products_order' );

you should add this to at the end of your child theme's functions.php file, but before a closing ?>, if any

Ronald

verityweb

Posted 23 July 2014 - 01:01 PM

I used the instructions here: ttp://ithemes.com/codex/page/Exchange_FAQs:_How_Do_I_Create_a_Custom_Product_Category_Page to create a custom category template and it worked great except that the order that I setup in Exchange Settings was not included.

I added the following custom query arguments to modify the order but the results are removing most of the products from the output including product images instead of merely changing the sort order.
		 <?php $args = array ('order' => 'ASC', 'orderby' => 'slug',);
		 $query = new WP_Query( $args );
		 if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
			
<?php it_exchange_set_product( $post->ID ); ?>
<?php it_exchange_get_template_part( 'content-store/elements/product' ); ?>	
	
		 <?php endwhile; ?>
		 <?php endif; ?>

How can I change the sort order?

Review the complete topic (launches new window)