Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author agentevolution

    (@agentevolution)

    The price is in a custom field on each individual listing. However to sort by price would require some logic to be built into the archive page that would remove dollar signs and commas from the price then sort. You may want to contact a developer to write that code for you.

    I recoded the archive listing theme template page to convert a copy of the price field to integer, and sort by status alphabetically then by price in descending order. See it below. This works for me because I only plan to use Active, Contingent, Pending and Sold statuses in that order, alphabetically. If you wanted to do more like filtering out SOLD or doing a different sort order, you’d have to change the code here. Keep in mind this is hard coded to the display output, so if you wanted to be able to change things dynamically via the settings, you would have to do more coding to the plugin.

    <?php
    /**
     * The template for displaying Listing Archive pages
     *
     * @link https://codex.www.ads-software.com/Template_Hierarchy
     *
     * @package WP Listings
     * @since 0.1.0
     */
    function archive_listing_loop() {
    
                    global $post;
                    $_listings = array();
    
                    $count = 0; // start counter at 0
    
                    // Start the Loop.
                    while ( have_posts() ) : the_post();
    
                            $_listings[$post->ID] = array();
    
    //                      $count++; // add 1 to counter on each loop
    //                      $first = ($count == 1) ? 'first' : ''; // if counter is 1 add class of first
    
                            $loop = sprintf( '<div class="listing-widget-thumb"><a href="%s" class="listing-image-link">%s</a>', get_permalink(), get_the_post_thumbnail( $post->ID, 'listings' ) );
    
                            if ( '' != wp_listings_get_status() ) {
                                    $loop .= sprintf( '<span class="listing-status %s">%s</span>', strtolower(str_replace(' ', '-', wp_listings_get_status())), wp_listings_get_status() );
                            $_listings[$post->ID]["status"] = wp_listings_get_status();
                            }
    
                            $loop .= sprintf( '<div class="listing-thumb-meta">' );
    
                            if ( '' != get_post_meta( $post->ID, '_listing_text', true ) ) {
                                    $loop .= sprintf( '<span class="listing-text">%s</span>', get_post_meta( $post->ID, '_listing_text', true ) );
                            } elseif ( '' != wp_listings_get_property_types() ) {
                                    $loop .= sprintf( '<span class="listing-property-type">%s</span>', wp_listings_get_property_types() );
                            }
    
                            if ( '' != get_post_meta( $post->ID, '_listing_price', true ) ) {
                                    $loop .= sprintf( '<span class="listing-price">%s</span>', get_post_meta( $post->ID, '_listing_price', true ) );
                            $_listings[$post->ID]["price"] = (int)preg_replace("/([^0-9\\.])/i", "", get_post_meta( $post->ID, '_listing_price', true ) );
                            }
    
                            $loop .= sprintf( '</div><!-- .listing-thumb-meta --></div><!-- .listing-widget-thumb -->' );
    
                            if ( '' != get_post_meta( $post->ID, '_listing_open_house', true ) ) {
                                    $loop .= sprintf( '<span class="listing-open-house">Open House: %s</span>', get_post_meta( $post->ID, '_listing_open_house', true ) );
                            }
    
                            $loop .= sprintf( '<div class="listing-widget-details"><h3 class="listing-title"><a href="%s">%s</a></h3>', get_permalink(), get_the_title() );
                            $loop .= sprintf( '<p class="listing-address"><span class="listing-address">%s</span><br />', wp_listings_get_address() );
                            $loop .= sprintf( '<span class="listing-city-state-zip">%s, %s %s</span></p>', wp_listings_get_city(), wp_listings_get_state(), get_post_meta( $post->ID, '_listing_zip', true ) );
    
                            if ( '' != get_post_meta( $post->ID, '_listing_bedrooms', true ) || '' != get_post_meta( $post->ID, '_listing_bathrooms', true ) || '' != get_post_meta( $post->ID, '_listing_sqft', true )) {
                                    $loop .= sprintf( '<ul class="listing-beds-baths-sqft"><li class="beds">%s<span>Beds</span></li> <li class="baths">%s<span>Baths</span></li> <li class="sqft">%s<span>Sq ft</span></li></ul>', get_post_meta( $post->ID, '_listing_bedrooms', true ), get_post_meta( $post->ID, '_listing_bathrooms', true ), get_post_meta( $post->ID, '_listing_sqft', true ) );
                            }
    
                            $loop .= sprintf('</div><!-- .listing-widget-details -->');
    
                            $loop .= sprintf( '<a href="%s" class="button btn-primary more-link">%s</a>', get_permalink(), __( 'View Listing', 'wp_listings' ) );
    
                            /** wrap in div with column class, and output **/
    //                      $output = sprintf( '<article id="post-%s" class="listing entry one-third %s"><div class="listing-wrap">%s</div><!-- .listing-wrap --></article><!-- article#post-## -->', get_the_id(), $first, apply_filters( 'wp_listings_featured_listings_widget_loop', $loop ) );
                            $_listings[$post->ID]["output"] = apply_filters( 'wp_listings_featured_listings_widget_loop', $loop );
    
                            $_listings[$post->ID]["post-id"] = $post->ID;
    
    //                      if ( 3 == $count ) { // if counter is 3, reset to 0
    //                              $count = 0;
    //                      }
    
                    endwhile;
    
                    foreach ($_listings as $key => $row) {
                            $status[$key]  = $row['status'];
                            $price[$key] = $row['price'];
                    }
                    array_multisort($status, SORT_ASC, $price, SORT_DESC, $_listings);
                    foreach ($_listings as $_listing){
    
                            $count++; // add 1 to counter on each loop
                            $first = ($count == 1) ? 'first' : ''; // if counter is 1 add class of first
                            printf( '<article id="post-%s" class="listing entry one-third %s"><div class="listing-wrap">%s</div><!-- .listing-wrap --></article><!-- article#post-## -->', $_listing['post-id'], $first, $_listing['output'] );
                            if ( 3 == $count ) { // if counter is 3, reset to 0
                                    $count = 0;
                            }
                    }
    
                    unset($_listings);
    
                    if (function_exists('equity')) {
                            equity_posts_nav();
                    } elseif (function_exists('genesis_init')) {
                            genesis_posts_nav();
                    } else {
                            wp_listings_paging_nav();
                    }
    
    }// end function
    
    if (function_exists('equity')) {
    
            add_filter( 'equity_pre_get_option_site_layout', '__equity_return_full_width_content' );
            remove_action( 'equity_entry_header', 'equity_post_info', 12 );
            remove_action( 'equity_entry_footer', 'equity_post_meta' );
    
            remove_action( 'equity_loop', 'equity_do_loop' );
            add_action( 'equity_loop', 'archive_listing_loop' );
    
            equity();
    
    } elseif (function_exists('genesis_init')) {
    
            add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
            remove_action( 'genesis_before_loop', 'genesis_do_breadcrumbs' );
            remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
            remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
            remove_action( 'genesis_after_entry', 'genesis_do_author_box_single' );
    
            remove_action( 'genesis_loop', 'genesis_do_loop' );
            add_action( 'genesis_loop', 'archive_listing_loop' );
    
            genesis();
    
    } else {
    
    get_header(); ?>
    
            <section id="primary" class="content-area container inner">
                    <div id="content" class="site-content" role="main">
    
                            <?php if ( have_posts() ) : ?>
    
                                    <header class="archive-header">
                                            <?php
                                            $object = get_queried_object();
    
                                            if ( !isset($object->label) ) {
                                                    $title = '<h1 class="archive-title">' . $object->name . '</h1>';
                                            } else {
                                                    $title = '<h1 class="archive-title">' . get_bloginfo('name') . ' Listings</h1>';
                                            }
    
                                            echo $title; ?>
    
                        <small><?php if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb('<p id="breadcrumbs">','</p>'); } ?></small>
                                    </header><!-- .archive-header -->
    
                            <?php
    
                            archive_listing_loop();
    
                            else :
                                    // If no content, include the "No posts found" template.
                                    get_template_part( 'content', 'none' );
    
                            endif;
    
                            ?>
    
                    </div><!-- #content -->
            </section><!-- #primary -->
    
    <?php
    //get_sidebar( 'content' );
    //get_sidebar();
    get_footer();
    
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Search/Archive Sort Order’ is closed to new replies.