WordPress.org

Ready to get started?Download WordPress

Forums

Post Sorting Reloaded
[resolved] Sorting by custom field (8 posts)

  1. Matachin
    Member
    Posted 3 years ago #

    Is any chance to sort posts by a custom field (I'm thinking of sort events by date not by publish date)

    http://wordpress.org/extend/plugins/post-sorting-reloaded/

  2. gab.ro
    Member
    Plugin Author

    Posted 3 years ago #

    I think it should be possible.

    Some SQL magic in the "Sort type" field could probably do it.

  3. peter213
    Member
    Posted 3 years ago #

    Nice plug in.
    a minor wish list.

    1. ability to add plugin in manually to templates
    2. add some classes to help specify what has been selected

    peter

  4. gab.ro
    Member
    Plugin Author

    Posted 3 years ago #

    Thanks Peter,

    1. You can always register a little sidebar in your functions.php, display it somewhere in your template and then add the widget there.

    2. Solved. If you upgrade to version 1.2 you can use the %class tag in the "Item format" field. It will either output class="psr-selected" or class="psr-deselected".

    Gab

  5. gab.ro
    Member
    Plugin Author

    Posted 3 years ago #

    Just wait a few minutes for the plugin directory to update.

  6. Laura McDonald
    Member
    Posted 3 years ago #

    There is a plugin that would sort by custom field, called wp-smart-sort, but it doesn't seem to be working in 3.1 anymore. Maybe if you look at that code you'd get some ideas or maybe even be able to fix and incorporate it into yours?
    http://wordpress.org/extend/plugins/wp-smart-sort/

  7. gab.ro
    Member
    Plugin Author

    Posted 3 years ago #

    I remember I looked at it's code a while ago, and much of the SQL seemed gibberish to me. I'm not that much of an SQL expert.

    Anyhow, if sorting by custom field is possible with the posts_orderby filter, all there would be to it, would be some SQL vodoo in the "Sort type" field, so there are no actual code improvements that I can do.

    All we need is an SQL expert to come and tell us what to write there. I'm guessing that joining some tables might be necessary...

  8. gab.ro
    Member
    Plugin Author

    Posted 2 years ago #

    Finally figured out how to sort by custom fields: see here.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic