Forums › Forums › Search & Filter Pro › Sort by Custom Post Type
Tagged: custom post types
- This topic has 9 replies, 2 voices, and was last updated 9 years ago by Ross.
-
Anonymous(Private) October 28, 2015 at 5:50 am #28389
Hi,
I have a site using custom post types and ACF.
There are currently 7 custom post types and I would like to be able to sort my results by these custom post types.
I have tried a number of the options in the Sort Order field but none of them seem to work.
Can someone please point me in the right direction.Cheers,
DanRoss Moderator(Private) October 28, 2015 at 12:05 pm #28422Hi Dan what do you mean sort by post type?
As in, sort by the post type name? So
Pages
would be appear beforePosts
?Thanks
Anonymous(Private) October 28, 2015 at 12:51 pm #28430Hi Ross,
Sorry for not being more clear.
I have staff info site using 7 different custom post types:
1 – General Info
2 – Licences
3 – Certificates
etc…At the moment the initial search results page sorts and displays the results by the date that these posts were created. Thats ok.
I have another Sort By filter which sorts the results by a specific taxonomy (Persons Name) that way I can see all custom posts grouped by name. However when I do select this sort order it will display the results by name and then date created so I get something like:
3 – Certificates – Bob Smith
1 – General – Bob Smith
2 – Licences – Bob Smith
3 – Certificates – Chris Jones
1 – General – Chris Jones
2 – Licences – Chris JonesI would like to get this:
1 – General – Bob Smith
2 – Licences – Bob Smith
3 – Certificates – Bob Smith
1 – General – Chris Jones
2 – Licences – Chris Jones
3 – Certificates – Chris JonesHopefully this makes more sense.
Cheers,
DanRoss Moderator(Private) October 30, 2015 at 10:17 am #28606Hi Daniel
I’m afraid the only sorting available is the options you see there under the “posts” tab.
However, saying that, you can modify the sort order yourself, just in the same way as a regular WP query using
pre_get_posts
:https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
http://wordpress.stackexchange.com/questions/180608/changing-sort-order-with-pre-get-posts-using-is-post-type-archive-doesnt-changeThanks
Ross Moderator(Private) November 17, 2015 at 12:13 pm #30000Hey Daniel
Apologies – I totally missed that in WP 4.0 support was added for ordering by post type:
https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
I’ve just added this to the plugin and emailed it to you, so you should now see the option to order by “Type”
🙂
Thanks
Ross Moderator(Private) November 17, 2015 at 12:15 pm #30001Ah sorry just re-read the rest of the messages again – I’m currently adding support for sorting by multiple fields too – this should be later on today/tomorrow.
Thanks
Ross Moderator(Private) November 17, 2015 at 5:59 pm #30037Hey Daniel
I’ve just sent you an update.
If you take a look under the “Posts” tab there is now also a secondary sort option.
It requires WP 4.0 or higher to use the secondary sort option – if using post meta to sort you must be using WP 4.2 or higher (we’re utilising some new features added to WP for sorting).
Thanks
-
AuthorPosts