Forums Forums Search & Filter Pro Sort by Custom Post Type

  • This topic has 9 replies, 2 voices, and was last updated 9 years ago by Ross.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Anonymous
    #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,
    Dan

    Ross Moderator
    #28422

    Hi Dan what do you mean sort by post type?

    As in, sort by the post type name? So Pages would be appear before Posts?

    Thanks

    Anonymous
    #28430

    Hi 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 Jones

    I 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 Jones

    Hopefully this makes more sense.

    Cheers,
    Dan

    Anonymous
    #28432

    So yes sort by Post Type name. My post types actually include the numbers 1, 2, 3… in them.

    Anonymous
    #28591

    Hi Ross,
    Any idea if this is possible?

    Cheers, Dan

    Ross Moderator
    #28606

    Hi 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-change

    Thanks

    Anonymous
    #29976

    Hi Ross,

    I still cannot get this to work using the results.php or my regular template loop.
    Have tried a bunch of stuff.
    Any chance of some detailed instructions on how to get this going?

    Cheers,
    Dan

    Ross Moderator
    #30000

    Hey 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
    #30001

    Ah 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
    #30037

    Hey 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

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