Viewing 1 replies (of 1 total)
  • Plugin Author agentevolution

    (@agentevolution)

    You’d need to write a custom function to remove dollar signs and commas from the price field, save it as a new meta field, and then sort by that.

    Here are some old functions, specific to Genesis Framework, that could work but you would need to update and customize:

    function clean_listing_prices() {
    
    	$args = array(
    		'numberposts' => 1,
    		'post_type'   => 'listing'
    	);
    
    	$listing_posts = get_posts($args);
    
    	$clean_price_field = get_post_meta($listing_posts[0]->ID, '_clean_listing_price', true);
    
    	if ( !empty($clean_price_field) ) {
    		return;
    	}
    
    	$args = array(
    		'post_type' => 'listing',
    		'posts_per_page' => -1
    	);
    
    	$lq = new WP_Query($args);
    
    	while ( $lq->have_posts() ) : $lq->the_post();
    
    		$price = genesis_get_custom_field('_listing_price');
    
    		$clean_price = preg_replace('/[\$,]/', '', $price);
    
    		$id = get_the_ID();
    
    		update_post_meta($id, '_clean_listing_price', $clean_price);
    
    	endwhile;
    }
    
    function wpl_ordered_listings_content() {
    
    	clean_listing_prices();
    
    	$args = array(
    		'post_type'    => 'listing',
    		'numberposts'  => -1,
    		'meta_key'     => '_clean_listing_price',
    		'orderby'      => 'meta_value_num',
    		'order'        => 'DESC',
    		'status'       => 'active'
    	);
    
    	$active_listings = get_posts($args);
    
    	$args['status'] = 'pending';
    
    	$pending_listings = get_posts($args);
    
    	$args['status'] = 'sold';
    
    	$sold_listings = get_posts($args);
    
    	echo '<h2 class="taxonomy-title">Active Listings</h2>';
    	wpl_iterate_posts($active_listings);
    
    	echo '<h2 class="taxonomy-title">Pending Listings</h2>';
    	wpl_iterate_posts($pending_listings);
    
    	echo '<h2 class="taxonomy-title">Sold Listings</h2>';
    	wpl_iterate_posts($sold_listings);
    
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Change the display order of listings’ is closed to new replies.