Sorting for Listing

This topic contains 11 replies, has 6 voices, and was last updated by  Paolo 8 years, 10 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket

Tagged: 

  • Author
    Posts
  • #6752

    PSI
    Free User
    Post count: 68

    Hi,

    I am looking to realize the sorting we need for our finder but I cant figure it out. For us there are two important groups which need to be sorted. First the Featured customers (paid account) and then the free entries. I would like to sort first always the featured customers alphabetically and after them there should be the free listings also alphabetically.

    Example:

    Anna (feat)
    Bert (feat)
    Chris (feat)
    Tony (feat)
    Albert (non feat – free)
    Steve (non feat – free)
    Tammy (non feat – free)

    Can you please tell me how todo this?

    Thanks guys!
    PSI

    #6757

    purpleedge
    Expired Member
    Post count: 539

    Have you tried the GD options for “Place”/”Sorting Options” tab

    See attached image

    #6778

    PSI
    Free User
    Post count: 68

    Yes I have tried but it seems to be that it is only possible to have one or the other option not both like I need it. I dont want to give the visitior the possibility to switch filters.

    Featured items have always to be listed on top…

    I hope this describes my problem

    #6810

    purpleedge
    Expired Member
    Post count: 539

    I haven’t experimented with these settings but I thought they way shown in the image would achieve what you want?

    I’m sure Paolo or Vikas will help.

    #6854

    Paolo
    Site Admin
    Post count: 31206

    That is currently not possible. You can sort by featured or alphabetically.
    Thx

    #6932

    PSI
    Free User
    Post count: 68

    Hi Paolo,

    Thank you for your reply. I have talked to Vikas and he said that he will have an eye on it. I think its a standard feature compared to other finder solution that should be implemented. In the meantime can you tell me where in the code the sorting will be done?

    Thanks
    PSI

    #6974

    Vikas
    Full Member
    Post count: 1128

    Plz try to put this code in your theme functions.php file

    
    
    
    
    add_filter('pre_get_posts', 'geodir_apply_my_posts_orderby');
    function geodir_apply_my_posts_orderby($query)
    {
    	if ( isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop']) {
    		if(!is_admin())
    			add_filter('posts_orderby', 'geodir_my_posts_orderby'  );
    	}
    
    }
    
    function geodir_my_posts_orderby($orderby)
    {
    	global $wpdb;
    	if(!is_admin())
    	{
    		$orderby = str_replace(", $wpdb->posts.post_date desc" , '', 	$orderby);
    	}
    	return $orderby ;
    	
    }
    

    Let me know if this works.

    Thanks for ur patience.

    #6978

    PSI
    Free User
    Post count: 68

    worked for me! brilliant support! Thanks Vikas

    #36910

    Joel Byrnes
    Buyer
    Post count: 1

    Just wanted to mention that the listing page does not sort alphabetically without the code provided here.. Even with the dropdown to change ascending/descending.

    I’m using latest version + multiLocations.

    #36924

    Paolo
    Site Admin
    Post count: 31206

    Hi Joel,

    I just tested here: http://wpgeo.directory/attractions/?sort_by=post_title_asc

    with latest everything and without that function and it works.

    Could you please provide a URL and wp admin credentials for us to see?

    Thanks

    #43883

    sebathustra
    Buyer
    Post count: 1

    Hallo,

    I would like to sort first always the featured customers randomly and after them there should be the free listings also randomly sorted.

    Is it possible to modify Vikas’ code to achieve this effect?

    
    
    add_filter('pre_get_posts', 'geodir_apply_my_posts_orderby');
    function geodir_apply_my_posts_orderby($query)
    {
    	if ( isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop']) {
    		if(!is_admin())
    			add_filter('posts_orderby', 'geodir_my_posts_orderby'  );
    	}
    
    }
    
    function geodir_my_posts_orderby($orderby)
    {
    	global $wpdb;
    	if(!is_admin())
    	{
    		$orderby = str_replace(", $wpdb->posts.post_date desc" , '', 	$orderby);
    	}
    	return $orderby ;
    	
    }
    #44010

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    no that is not possible.

    Thanks

Viewing 12 posts - 1 through 12 (of 12 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket