Support

Home Forums Event Espresso Premium People Add-on – Order people or people-type list alphabetically by last name

People Add-on – Order people or people-type list alphabetically by last name

Posted: January 7, 2016 at 9:56 am

Viewing 4 reply threads


Daniel

January 7, 2016 at 9:56 am

I’m using the People Add-on.
How can I order the people list or people-type list alphabetically by last name?


Tony

  • Support Staff

January 8, 2016 at 4:26 am

Hi Susan,

Is this within the admin or on the front end, if the front end within the event itself?

If within the admin you can not currently order by Last name, only full name but clicking ‘Name’ – http://take.ms/Cw65D

Types can also be order by clicking on name within that section – http://take.ms/fjd0O

If within the front end you’ll likely need to create custom templates to alter the query but it depends on where you are looking at as to which template.


Daniel

January 8, 2016 at 6:09 am

Tony,

Thanks for your reply.
I am not concerned about the admin (backend).

I need to order the people for the front end. I actually need to have 2 specific people (program directors) at the top of the list and the remaining people sorted alphabetically by last name.

I use the WP Post Types Order plugin to “effortlessly” re-order posts using drag and drop. Ideally I would like to be able to do this with the People I add to the list in the People Add-on but it is not currently possible.

Is this something you would consider adding to your plugin?

Could you please suggest the easiest way I could achieve what I’m trying to do. I am technical/a developer but I don’t have experience with creating custom templates. If you could point me in the right direction it would be helpful.

Thanks!
Janet (Susan’s web developer)


Josh

  • Support Staff

January 8, 2016 at 3:26 pm

Hi Janet,

In the case of re-ordering the posts, you can use the WordPress plugin API’s posts_orderby filter. There is some basic info about how to use this filter in the codex:

https://codex.wordpress.org/Plugin_API/Filter_Reference/posts_orderby

In this case, the JOIN that’s involved gets the last name field from the database table where it’s stored. Which oddly enough is the attendee meta table, who knew!?

Anyway, the readymade code in this snippet can be dropped into your theme’s functions.php file to get that part done:

https://github.com/eventespresso/ee-code-snippet-library/blob/master/addons/eea-people/jf_eea_people_archive_orderby_lname.php

In the case of placing the program directors at the top of the list, that’s typically done in WordPress by running multiple loops. The first loop does the first list of the program directors, where the program directors could be in their own People category, then the second loop lists everyone else. There’s a really great example of how to set up multiple loops in the WordPress codex that you can follow:

https://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action


Daniel

January 9, 2016 at 10:52 am

Thanks so much for your help Josh.

Your code to order by last name worked but in the end I’ve gone with this function to reverse the order so it shows people by id number ASC.

// re-order people Archive so it's ASC by id
function order_people_by_id( $query ) {

    if ( $query->is_post_type_archive( 'espresso_people' ) ){
		$query->set('orderby', 'id');
		$query->set('order', 'ASC');
    }
}
add_action( 'pre_get_posts', 'order_people_by_id', 1 );
Viewing 4 reply threads

The support post ‘People Add-on – Order people or people-type list alphabetically by last name’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso