Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By tslice08

Thread: Problem with default sorting

  1. #1
    Thread Starter
    tslice08's Avatar
    Join Date
    Jul 2014
    Location
    United States
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with default sorting

    Currently the "Default" sorting method functions the same as "Newest", except Featured listings appear first.

    This gives newer listings a placement advantage, appearing directly below the featured listings, thus penalizing established listings by placing them further down the list.

    Random ordering would make more sense for the default setting: Featured ads remain at the top, just as they are now, and all other listings below are randomly ordered so newer listings aren't given an advantage.

    On their own, the "Newest" and "Random" sort methods do not place featured listings at the top, so they are not appropriate choices.


    Below is part of the core.php code that goes into sorting. What tweaks are necessary to cause the default sort method to still place featured listings at the top, but to order all remaining listings randomly instead of by date?


    PHP Code:
    $orderby $va_options->default_listing_home_sort;

        
    $args['orderby'] = $orderby;
        
    $args['va_orderby'] = $orderby;

        switch ( 
    $orderby ) {
            case 
    'highest_rating':
                
    $args['meta_key'] = 'rating_avg';
                
    $args['orderby'] = 'meta_value, comment_count';
                
    $args['order'] = 'desc';
                break;
            case 
    'most_ratings':
                
    $args['orderby'] = 'comment_count';
                
    $args['order'] = 'desc';
                break;
            case 
    'newest':
                
    $args['order'] = 'desc';
                break;
            case 
    'recently_reviewed':
                    
    $result_ids $wpdb->get_col$wpdb->prepare"SELECT DISTINCT p.ID FROM $wpdb->posts p LEFT JOIN $wpdb->comments c ON p.ID = c.`comment_post_ID` WHERE p.`post_type` = '%s' ORDER BY c.`comment_ID` DESC"VA_LISTING_PTYPE ) );
                    
    $args['orderby'] = 'post__in';
                    
    $args['post__in'] = $result_ids;
                break;
            case 
    'rand':
                
    $args['orderby'] = 'rand';
                break;
            case 
    'title':
                
    $args['orderby'] = 'title';
                break;
            case 
    'default':
            default:
                
    $args['meta_key'] = 'featured-home';
                
    $args['orderby'] = 'meta_value_num';
                
    $args['order'] = 'desc';
                
    $args['va-featured'] = true;
                break;
        }

        
    $query = new WP_Query$args );
        return 
    $query;
    }

    add_filter'posts_clauses''va_featured_random_sort'10);
    function 
    va_featured_random_sort$clauses$wp_query ) {
        global 
    $wpdb$va_options;

        if ( 
    $wp_query->get'va-featured' ) ) {

            
    $post_types = array();
            
    $post_types[] = VA_LISTING_PTYPE;
            if ( 
    $va_options->events_enabled ) {
                
    $post_types[] = VA_EVENT_PTYPE;
            }

            
    $post_type = isset( $wp_query->query_vars['post_type'] ) && in_array$wp_query->query_vars['post_type'], $post_types ) ? $wp_query->query_vars['post_type'] : VA_LISTING_PTYPE;
            
    $featured_option $post_type 's_featured_sort';

            switch ( 
    $va_options->$featured_option ) {
                case 
    'oldest':
                    
    $clauses['orderby'] .= ", $wpdb->posts.post_date ASC";
                    break;
                case 
    'newest':
                    
    $clauses['orderby'] .= ", $wpdb->posts.post_date DESC";
                    break;
                case 
    'random':
                default:
                    
    $clauses['fields'] .= ", if( ( `$wpdb->postmeta`.meta_value > 0 ), ( `$wpdb->postmeta`.meta_value + RAND() ), 0 ) as _va_featured_hash ";
                    
    $clauses['orderby'] .= ", _va_featured_hash ASC, $wpdb->posts.post_date DESC";
                    break;
            }
        }

        return 
    $clauses;

    chel_ likes this.

  2. #2
    Expired Customer chel_'s Avatar
    Join Date
    Jun 2015
    Posts
    18
    Thanks
    5
    Thanked 0 Times in 0 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  3. #3
    Expired Customer chel_'s Avatar
    Join Date
    Jun 2015
    Posts
    18
    Thanks
    5
    Thanked 0 Times in 0 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Sorting doesn't work on default pagination
    By manishkhullar in forum Jibo
    Replies: 1
    Last Post: September 10th, 2014, 08:06 AM
  2. Samcy How to make default ad sorting by "views" and not date
    By graphicpilot in forum Help Using ClassiPress
    Replies: 1
    Last Post: July 1st, 2014, 05:21 AM
  3. [SOLVED] Sorting by date problem
    By philipm in forum Shortys for ClassiPress
    Replies: 5
    Last Post: June 5th, 2014, 05:58 AM
  4. [SOLVED] Sorting Default ?
    By archersoftech in forum Vantage General Discussion (Legacy)
    Replies: 4
    Last Post: June 16th, 2013, 07:08 AM
  5. Images - problem sorting re-ordering from edit listing
    By megamind in forum Report Vantage Bugs (Legacy)
    Replies: 1
    Last Post: December 21st, 2012, 12:35 PM