Post Sorting Reloaded

Warning: This plugin is no longer supported. It’s functionality has been included into a new plugin called Nano Plugin Manager.

A little history first for whoever might be interested. I was asked to write the WP Post Sorting plugin while working at Reflection Media. Now I no longer work there (or anywhere else for that matter), but I don’t want to abandon the plugin, so I made this fork.

Like the old one, this plugin is basically just a wrapper for the posts_orderby filter. But while the old plugin only had category sorting abilities, this new one is a complete wrapper. What does this mean? That you can use any combination of conditional tags and any return value for the posts_orderby filter.

A screenshot will explain everything.

Isn’t a picture worth a thousand words?

People familiar with WordPress plugins will immediately see the concept similarity with the Widget Logic plugin, so I’d like to thank it’s developer for inspiration.

The plugin is available for download on WordPress Extend.

116 comentarii la “Post Sorting Reloaded

  1. I have installed the plugin on my site since this is just the thing I need, however since my categories are all in Cyrillic the plugin does not work. Could you please fix this issue by updating the plugin to work with Cyrillic symbols and categories as well. Thanks a million !!!

  2. Hi Dimitar,

    I’ll try to look into it next week. Just a quick idea: for the is_category conditional tag, you may also use the category ID: is_category('9')

    Have a nice weekend.

  3. Well, I’ve just tested it with is_category('подтикна') and it seems to be working properly. For further testing, please deactivate all other plugins and try it with the default WordPress theme. What error message are you getting?

  4. Hello Gab,

    Just tried again, the Cyrillic symbols still do not seem to work. I have also tried using the category ID as per your suggestion, however that does not seem to work as well. For your convenience I am attaching a link to a screen shot that I have made, I hope you find this useful :

    http://kry4mi.com/test.jpg

    At the moment the plugin is activated, however affecting the post’s order only once you are into to category pages, meaning that the home page is not effected. For example if I choose is_category(’32’) and post_date ASC and go to the page of category 32 it is working properly, meaning that the oldest article is shown first. However as I said, still not effecting the home page.

    P.S.: I do not get any error message and turning all the other plugins that I have is not really an option as well.

  5. Hi again Dimitar,

    Now I understand what’s going on. There is a misunderstanding regarding what this plugin actually does.

    When you choose a specific sorting type for a certain category, this plugin will sort all post on that category page accordingly. However it does not and can not do anything for your home page, unless you use the is_home() conditional tag, in which case all posts on your home page will be sorted.

    The misunderstanding can also be seen on your screenshot. It does not make any sense to use the is_sticky() conditional tag, since it does not apply to any loop page, but only to single posts.

    Best of luck,

    Gab

  6. Dear Gab,

    Thank you for the clarification, I will surely take care of this right away. I would also like to kindly thank you for the attention and wish you all the best of luck with your future projects.

    Have a truly wonderful day !

    Cheers from Bulgaria
    Dimitar

  7. I get the following error message after installing your plugin…any help would be appreciated.

    Parse error: syntax error, unexpected ‘}’ in /var/www/html/wp-content/plugins/post-sorting-reloaded/includes/psr-posts_orderby.php(12) : eval()’d code on line 1

  8. Hello!

    What condition are you using? You should have no curly brackets { } there. Instead, just use regular round brackets ( ).

  9. Good stuff, Gab. Two questions:

    1) Any chance you can add an “ignored words” capability so that we can tell alphabetical sorting to ignore articles, such as the English-language “a” “an” and “the”? This exists in AStickyPostOrderER, but the implementation didn’t work for me at all. I just want what you’ve created: sorted categories.

    2) Can I force it to work with any child category of a parent that should be sorted? Is there an appropriate conditional that looks like is_category_child(‘books’) – to test if the category is a child of ‘books’.

  10. Thanks Jack, it’s nice to see people dropping by from time to time. I’m feeling a bit underappreciated here :)

    As for your two questions:

    1) Some MySQL magic will do the trick. Just replace post_title with REPLACE(post_title, 'The ', '')

    Don’t forget putting a space character after the ignored word.

    If you want to ignore more words, just replace again post_title with REPLACE(post_title, 'An ', '')

    So that your final code will look like REPLACE(REPLACE(post_title, 'An ', ''), 'The ', '')

    You can do this as many times as you want.

    2) You need to use the cat_is_ancestor_of conditional tag. The code you want is

    cat_is_ancestor_of(3, get_query_var('cat'))

    …where 3 is the ID of your ‘books’ category. You must use the ID in this case. The slug or name won’t work.

  11. Gab, this is awesome. Thanks and exactly what I needed. Plug-in successfully installed and working for my Books category in a new WP blog – not even released yet, or I’d point you to it.

  12. OK, I’ve tested it on the Twenty Ten theme and everything appears to be working fine. Sticky posts are displayed at the top of the front page (and sorted according to the PSR rules), and regular posts are displayed below the sticky posts, and also sorted according to the PSR rules.

    This seems to be the behavior you asked for.

    Exactly what behavior are you getting?

  13. I think the problem I’m having is that since I am trying to use WordPress as CMS. So, when I do a category listing, I would like a specific entry up at the top (sticky). And this is not happening. For example: http://www.p3cg.com/cms/category/books/ this page should show “The Goal” as the first book. It works fine on the “home” page: http://www.p3cg.com/cms/resources/

    [These links are from a testing site, so they will probably vanish after a few days.]

  14. Some interesting books there… OK, so did you try deactivating my plugin and see if then you get your sticky posts at the top of category pages? If this is the case (and I suspect it is), your issue is not related to the plugin, it’s just your theme’s default behavior.

    WordPress is great as a CMS, you just need to customize your theme a little bit, maybe edit your theme’s categories.php

    Just google wordpress sticky post category.

  15. Perfect. That was the piece I was missing. There is a AStickyPostOrderER that I had picked up but its functionality is a little odd. It doesn’t use the “sticky” capability in WordPress (maybe written before that was created), so I have to explicitly order the posts that are supposed to be stuck at the top. And in combination with Post Sorting Reloaded, I get the behavior I want.

    Thanks again, Gab.

  16. Hello Gab,

    I have just installed your plugin and set the conditions 1 to comments_open() – post_date DESC. On my website there is only one page open for comments, the blog page. But nothing happens to the sorting of the comments there. I have also used page_ID and some others but still nothing happens. I am using wordpress 3.0.3. What do I do wrong.

    Best
    Thomas

  17. Hello Thomas,

    As the name suggests, this plugins is for sorting posts, not comments. If you want to reverse the order of your comments, you might want to take a look at your theme’s comments.php, specifically at the wp_list_comments() function and it’s arguments.

    Regards,
    Gab

  18. Oh, and apparently there’s also an option in the Settings -> Discussion panel:

    “Comments should be displayed with the older/newer comments at the top of each page.”

  19. What type of sorting do you need for your sticky posts? And what type of sorting do you need for your regular posts? I think that it might be impossible to have different sorting types for each case.

    Perhaps you will find some inspiration in Jack Vinson’s comments. He said that a plugin called AStickyPostOrderER did the trick for him.

    Good luck with your project!

  20. Powerful plugin and works as advertised. I am interested in seeing how far the plugin can be pushed in its current state or hack or add this functionality to the plugin.

    I’m looking to sort the column post_content in the database and SUBSTRING the content starting at a specific starting point with a specific length using some kind of SUBSTRING function and sort the WordPress posts in Numeric order.

    At the start of each post content on my site I have inserted a numeric price value and I would like to be able to sort by price. Now it will sort only the first character in the numeric variable and not the value of the whole number. 1439.00 sorts before 9.00 in ASC order.

  21. Sorry. It went into spam for some reason.

    All your answers lay in MySQL functions. I’d just remove the point and then convert to integer. You could also probably convert directly to float.

  22. Hi,

    First off, I LOVE this plugin. It’s just what I’ve been after.

    I have it sorting all archives by comment count, which is working perfectly. I also wanted to have it sort Search Results by category too.

    So I have used the is_search() tag, but it’s not doing anything. Have you got any ideas on why this might be?

    Thanks in advance!

  23. Hey! I’m glad it helps.

    The is_search() tag is working properly. I’m guessing that the problem lays in your sort type. Have you tried another sort type, such as post_title for instance? Does it work?

    What exactly do you mean when you say “sort by category”? What if a post is in multiple categories? I think sorting by category might be a bit difficult. Some SQL magic may do the trick, but I’m not sure.

  24. Sorry, my bad. That was a typo… I meant to sort Search Results by Comment Count… (That is what I’ve been trying – not category!)

    I have just tried what you have said and sorted by Title and that has not worked either.

    Any more ideas?

  25. Well, it works for me. Try it while using the default theme and with all other plugins deactivated. The cause might be some weird search functionality included in your theme or in some plugin.

  26. Thanks, that was very simple… I have been using Relevannsi (the plugin to improve search relevance) and obviously that was over-riding the Sorting I was trying. When I deactivated just that it started working.

    Now all I need to do is find a way to exclude certain posts/categories and provide more reliable search results like Relevannsi did for me, and I’ll be sorted!

  27. Hey,

    thanks for the awesome plugin. I still wonder why this isnt customly built into wordpress. I have needed it for almost all my sites…

    Anyways, just wanted to say how much I appreciate your work!

  28. Using this plugin, I think there’s no way to sort just the sticky posts.

    Sticky posts are displayed at the top of the front page (and sorted according to the PSR rules), and regular posts are displayed below the sticky posts, and also sorted according to the PSR rules.

    Some SQL voodoo in the sort type field might do the trick, but I’m not that much of an SQL expert. All this plugin does is wrapping the posts_orderby hook in an user friendly manner.

  29. Hi! I like your plugin, and want to use it to sort by post title, which works fine.
    My problem is not really with your plugin, but is only noticed when I use it.
    If I sort by anything other than the default (date), and click to a single post, the navigation links for next and previous make no sense because they are arranged by date.
    Do you see a way to convey the list context to the single post, so the navigation can be the same as the list?

  30. Hi! Thanks. I remember looking into this a while ago, and my conclusion was that the chronological sorting is very much hardcoded into the navigation functionality. I’m not aware of an easy way of doing what you want to do.

  31. Yes, I discovered that as I looked at the code of WordPress.
    I thought to use the Cookie Monster Plus plugin to set a cookie for the sort query variable and then use that in my links, but it is too far away from what needs to happen.
    Maybe there is a way to set a cookie for the whole URL and then use that in the links instead of the built-in navigation links.
    Or I’ll end up leaving navigation links off of the single posts.

  32. If the navigation links are not all that important for you, removing them all together might be the optimal solution… WordPress was originally just a blogging software, and this is still haunting us.

  33. Gab! First of all, great job! simple and working great!

    I’m looking to see if I can fit this to what I need for my website, maybe you can help.

    First of all, is there any way to get them sorted randomly? If that’s possible, is it possible to always hold the latest one (based on some condition) at the top, and the rest sorted with a different way – randomly for example.

    On a second note, is there a way to give the option – maybe with a dropdown menu – to the users on how to get the posts sorted?

    Thanks for everything and congrats again for a great plugin!

  34. Hello Juan,

    For sorting them randomly, you can just use RAND()

    For having one at the top, you can use sticky posts.

    For giving the option to the users, use the widget.

    Thanks for using the plugin!

  35. Hey Gab,

    Just want to be sure I know how to accomplish what I need to with your plugin. I have several post categories and simply want them to sort by title within each category from the first to the last. Since I’m not clear on the post-orderby filter, could you tell me specifically how I’d need to configure your plugin to make that work? Thanks for your help!

    Kevin

  36. Hey!

    You just need one condition: is_category()

    And the sort type you need is: post_title ASC

    Cheers,

    Gab

  37. Your plugin just solved my 2010 problem of showing posts oldest first, but it leaves a “<" at the top of the page. I am having trouble figuring out where to find and fix it. Thank you for an awesome plugin!

  38. This is extremely odd.

    Are you sure my plugin is causing this? Did you try deactivating it to see if the problem persists?

    What version of the plugin are you using?

    Also, please try deactivating all other plugins except for this one, and then see if the problem persists.

    What settings for the plugin are you using?

  39. Hi there!

    I installed your plugin which is just what I need, but I can’t make it work :s

    Could you please help? I fill the condition and sort type, but wont work.

    I tried to sort my category lemezismertetok, which is category id 119. So my settings looks like this:

    Condition 1: is_home() Sort type 1: post_date DESC
    Condition 2: is_category( ‘119’ ) Sort type 2: post_title ASC

    Could you please check it out?

    Thansk in advance!

  40. Sorry, it works like a charm, just another post sorter plugin messed up which I disabled and now everything is fine.

    May I ask if there is an option, to use your sorter plugin in a dropdown box, where users can choose which sort option would they use?

  41. Hello! I’m glad to hear it all worked out fine.

    Yes, there is an option to use the plugin in a dropdown box: a widget is included in the plugin, you just need to use it :)

  42. Salut,

    In primul rand vreau sa-ti multumesc pentru un plugin extraordinar.

    Reusisem sa fac cateva functii care imi sortau posturile din categorii, dar nu am putut sa fac acelasi lucru pentru arhive. Plugin-ul tau m-a scutit de multe dureri de cap.

    Totusi, am o intrebare. Exista vreo cale sa folosesc functionalitatea din widget, fara a-l pune intr-o zona destinata lor?
    Lucrez la o tema noua pentru blog-ul meu si vreau ca linkurile de sortare sa fie pozitionate deasupra posturilor (titlul paginii in stanga, sortarea in dreapta).

    Exista vreo cale prin care pot seta optiunile widget-ului sa apara pe aceeasi pagina cu optiunile plugin-ului, ca apoi sa le afisez in pagina printr-un template tag?

    Multumesc! :-)

  43. Salut,

    Merci pentru apreciere :)

    Cea mai simplă metodă ar fi, după mine, să-ți definești o zonă de widgeturi special pentru asta și să o folosești doar cu widget-ul ăsta.

    O altă metodă:

    Probabil ai văzut că link-urile din widget te duc la adrese de forma: site.ro?sort=3 și așa mai departe. Ai putea să-ți pui widget-ul altundeva, după aia să-ți definești sortările pe care le vrei, să-ți notezi ce număr corespunde fiecărui tip de sortare, să scoți widget-ul și apoi să-ți hardcodezi linkurile alea cumva în template.

    N-ar prea avea sens ca setările widget-ului să fie pe pagina globală de opțiuni a plugin-ului pentru că mai nou, widget-urile din WordPress sunt gândite să poată fi folosite de oricâte ori, deci ar fi vorba despre un număr nelimitat de seturi de opțiuni.

  44. Hi Gab, thanks for this great plugin!
    I need some functionality that I guess it is beyond the scope of this plugin.
    I would like to change the post sorting order from within a link.
    The posts in the homepage are ordered by popularity and would like to provide a link to order the posts by date.
    Is there an easy way to do this without messing with query_posts or similar?
    Thanks!

  45. Hey Enrique, thanks!

    Maybe you can try using the widget included in this plugin. “post_date DESC” could work.

  46. Hi Gab, thanks for your great plugin!

    I have a problem with sorting posts in ClassiPress WP Theme. All posts have a Custom Field named “price”. How to sort posts by Custom Field “price”?
    I guess the problem is that Custom Field “price” is not a number than text.

    Thanks!

  47. Hi Dragoslav,

    I think that the problem you mention is not the biggest one. The thing is I still don’t know if it is possible to use the posts_orderby filter to sort posts by costom fields.

    As mentioned here.

  48. Update: I now know for a fact that sorting by custom fields does not work with the plugin as it is right now. But it will in a future version.

  49. I am trying to get your plug-in to work but I have either no luck or am using it all wrong.

    I would like to have all the posts in my blog with the Category ‘codegeneration’ placed at the top of my blog list, sorted descending on date. I have entered the following values:

    Condition 1: in_category( ‘codegeneration’ ) Sort type 1: post_date DESC

    but the sort order is still the default date descending order. What am I doing wrong?

  50. Yes, you seem to be using it all wrong.

    In the condition field you should specify the page where you want your posts to be sorted, like specific category pages, search pages, home page, etc.

    So you would use IS_category, and when you view that category, your posts will get sorted by the sort type that you choose.

    IN_category is a conditional tag that can be applied only to specific posts, so it makes no sense to use it in the condition field.

  51. awesome plugin man, wow! one question – is it possible to place the user selected sort options in my php template files instead of having to use the widget?

    if so what would be the code for that?

    thanks again!

  52. Hey! I think that the most straightforward way would be to just define another widget area specifically for this widget.

  53. I have been looking into the option for dynamically sorting posts.

    The issue with sorting numeric values is that there is an updated sort type –
    meta_valu_num.

    So by adding the following code to the themes function code allows for you to sort by a custom field, in this case designated as price:

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


    add_filter('posts_join', 'my_posts_join');

    function my_posts_join($join){
    global $wpdb;
    $join .= " LEFT JOIN $wpdb->postmeta wpmeta ON ($wpdb->posts.ID = wpmeta.post_id AND wpmeta.meta_key = 'price' )";
    return $join;
    }

    You can then update the sort type within the plugin widget to wpmeta.meta_value DESC, for example, however the proper sort type – wpmeta.meta_value_num DESC is not recognized.

    This is an important plugin / feature. Ideally the query_posts function can optionally reload internally within a page through jquery or ajax, etc.

    Gab, let us know how we can help take this plugin to the next level to allow for total control over query_posts sorting.

  54. I’m not sure I understand what you’re asking me.

    What I understand: you need to sort by the numeric value of a certain custom field.

    For doing this, I suggest using ABS(wpmeta.meta_value) DESC as your Sort Type.

    This is also mentioned at the end of the FAQ page.

    Don’t forget to also insert the posts_join code snippet.

  55. That is correct, I was looking to sort by a numeric value, however ‘sortby’ => ‘meta_value_num’ would be necessary in order to accurately sort custom field numbers. I thought I may be able to update sort type – wpmeta.meta_value DESC and use sort type – wpmeta.meta_value_num DESC, however it is not supported.

    I ended up writing a custom script but it would be a useful addition to your plugin.

  56. Hi Gab, I was able to install and run the plugin nice and smoothly. I was also able to create a custom field sorting option. The only thing I can’t figure out, is how do I create more custom field options. For instance I need one for ‘Price’ and one for ‘Date of Release’. In function.php, how would I customize the function for as many custom fields as I need?. Thanks in advance for your reply.

  57. Hi Francesco,

    What you need to do is duplicate the function with a different name (let’s say my_posts_join_second) and inside that function replace “wpmeta” with “whatever” (in all three instances).

    Also, don’t forget to add your second function to the posts_join filter, just like you did with the first.

    And don’t forget to change your meta_key to name your second custom field that you need.

    Now, you can sort by your second custom field by writing whatever.meta_value in the Sort Type field.

    You can do this with as many custom fields as you need.

  58. Hi Gab, thanks a million for your help, I tried what you suggested but that doesn’t seem to work. Below is what I did:

    add_filter('posts_join', 'my_posts_join');

    function my_posts_join($join){
    global $wpdb;
    $join .= " LEFT JOIN $wpdb->postmeta wpmeta ON ($wpdb->posts.ID = wpmeta.post_id AND wpmeta.meta_key = 'views')";
    return $join;
    }

    add_filter('posts_join_second', 'my_posts_join_second');

    function my_posts_join_second($join){
    global $wpdb;
    $join .= " LEFT JOIN $wpdb->postmeta wpmeta_second ON ($wpdb->posts.ID = wpmeta_second.post_id AND wpmeta_second.meta_key = 'Regista')";
    return $join;
    }

    I also tried changing the $join variable name, but that didn’t work either.

    As a matter of interest, below is the sort type I have used:
    wpmeta_second.meta_value ASC

    Thanks for your kind help :-) I know it looks really simple to you, but my php skills aren’t great.

  59. Allright! You’re almost there. The only mistake that pops into my eyes is that you used posts_join_second as a filter name. You should replace it with posts_join. You need to hook both of your functions to the same filter, namely posts_join.

    Take a look at the Filter Reference on the Codex. No posts_join_second filter there :)

  60. Yes! that worked like a charm despite the fact that I feel a bit stupid :-)
    Thanks Gab, you were super helpful.

  61. Hi there, I was wondering if your plugin supports custom taxonomies. I’m using the MarketPress Lite and All-in-one Event Calendar plug-ins and they both have custom categories.

    Would your plugin work with them?

  62. Hey! Do you need to sort posts in custom taxonomy pages or do you need to sort posts by some custom taxomomies?

  63. I’d be lying if I said I completely understood what taxomomies are. :-)

    However, with my limited understanding I’m guessing that I want is to sort posts in custom taxonomy pages.

    I have ‘posts’ that are actually products or calendar events, and they do not appear under the standard /categories/ URL, but under their own URLs (/store/categoriers/ for example.)

    If you had a look at either MarketPress Lite or All-in-one Event Calendar you’d probably understand better what I’m asking. They both utilize custom post and category lists.

  64. Hi, thanks for a great plugin but I cant seem to find the logic for the sorting I am trying to acheive. I have a list of Authors in catogories. For example ‘All Authors’ – ‘Authors A to C’ – ‘Authors D to E’ etc What I am trying to do is sort the author posts, in each catogory, alphabetically. Is that possible? I cant use post_title as that is the real word name of the Author and was hoping to use post_tag, which I have made surname/christian name, but that tag dosnt exist. Many thanks in advance for your help.

  65. First of all, your condition:

    Do you want to sort all your category pages or just some of them? If you want to sort all category pages you need the is_category() condition. If you want to sort just some of them, what you need is is_category(2,5,8) where 2,5,8 are category IDs.

    Secondly your sort type:

    Are all your posts „authors”? Is the post_title the author’s name. Such as, let’s say Ernest Hemingway? Is your problem the fact that you need to sort it by second name (letter H) and first name (letter E)?

  66. Hi, firstly thanks for your quick reponse. At the moment all Catogories are Authors, then they are sub divided A to C, D to E etc. Thats exactly my problem ;

    ‘Are all your posts „authors”? Is the post_title the author’s name. Such as, let’s say Ernest Hemingway? Is your problem the fact that you need to sort it by second name (letter H) and first name (letter E)?’ Yes thats correct, added to which some Authors have titles such as Doctor, Professor etc

    I know I can simply rename them – Surname – Christian Name – Title and it will all work but it dosnt look very good on the page. Thanks again if you can think of a way of acheiving this…come to think of it, thanks anyway! :)

  67. Yes. Replace post_title with:

    mysql_function(post_title, 'some_argument', 'another_argument')

    I have the function in my other browser tab. Can you find it? If you can’t in 30 minutes, let me know and I’ll give you a clue :)

  68. Hi, sorry, I am not sure what you mean by ‘my other browser tab’…..am I just being daft? :) I like the mystery…but I am confused enough!!! ha ha

  69. Nevermind that. I was just pointing out that I have the function in front of my eyes. Trying to motivate you, I guess.

    So. 30 minutes from now: 11:49, Romania time :)

  70. Ah got you! I thought the function was hidden somewhere in the depths of your site!….told you I was being daft! Its been a long day! :)

  71. OK, time’s up. First clue: the function you need is on this page.

    I’m going to bed now and I’ll be up and running in about 9 hours. If you still cant figure everything out by then, I’ll tell you the answer…

  72. I’m trying to teach you how to fish but you just want your fish. Here it is:

    SUBSTRING_INDEX(post_title, ' ', -1)

    How difficult was it? You haven’t even tried.

  73. post_title is the string you want to work on

    ‘ ‘ is the separator (just a space)

    the minus sign tells the function to start counting from the right

    1 tells it that you only want the last word

  74. Thanks I will give it a go now and let you know…..fishing is fine as long as you know what a hook is for! :)

  75. Your a genius! Xmas card on its way….when you give me your address!? But on a more serious note, do you do freelance work? I may have some work for you from time to time.

    Once again, many thanks.

  76. Hello, Gab.

    I am using this plugin and very happ, big thanks for your hard work. And I am using post sorting by meta key also. But I found sorting is still work when I am using new WP_Query somewhere in my theme template files. For example, I have main query in category.php (for list lowest price products first) and second query in sidebar.php (for list latest blog posts). And second query in sidebar is not sorting blog posts in the way I want it.

    Here is the code I’ve added to my functions.php:
    add_filter('posts_join', 'my_posts_join');

    function my_posts_join($join){
    global $wpdb;
    $join .= " LEFT JOIN $wpdb->postmeta wpmeta ON ($wpdb->posts.ID = wpmeta.post_id AND wpmeta.meta_key = 'price')";
    return $join;
    }

    And my plugin options are:

    Condition 1: is_category('blog') Sort type 1: post_date DESC
    Condition 2: is_category() Sort type 2: ABS(wpmeta.meta_value)

    I am using wordpress 3.2.1 but planning to update it to 3.3.
    I am really want to solve this problem if you can help me.

  77. So the problem is that your second query is sorting posts just like the main one?

    From what I can tell, the only way out of this is using some parameters (order, orderby) for one of your WP_Queries and leave just one to be handled by the plugin. Preferably the main one.

  78. Thank you for your reply.

    I am using order and orderby parameters in my second query. And it still sorting by meta value = price. The order and orderby parameters in second query does not have any effects, and posts are sorting like the main query.

  79. I’m glad you found this problem too. What do you mean it works both with query_posts and get_posts? You mean the wrong sorting?

    What should I do to fix this? Can you help me?

  80. Nemezis, what I was saying was that instead of building your secondary loop with WP_Query, you can use either query_posts or get_posts to do it.

    But while searching for this, I’ve also found a way to do it with WP_Query. All you need is to use the argument: 'suppress_filters' => true

  81. Thank you so much for this solution. I’ve tryed this with my second WP_Query and it solve my problem. Much more appreciate.

    Never heard about “suppress_filters” argument, because it’s shown only at get_posts wordpress codex page, not the WP_Query.

  82. Hi!
    The widget you made is what I am looking for to let user sort my Custom Posts.
    My Custom Posts are called Literature and then in a sidebar users could sort by ‘date posted’ / ‘date that the book was published’ & ‘authors’ (=taxonomies). Would be great. Is this be possible?

  83. Great plugin – being able to sort by post name has been awesome…unfortunately, our posts are addresses (basically, a real estate site) and many users want the ability to sort by street name – and I took what you mentioned a while to someone else about the replace function, and was trying to use a regex type function to account for all street #’s, as well as tried to have it skip the first word entirely but cant seem to figure it out.

    Do you know how I can use this: REPLACE(post_title, ‘1001 ‘, ”), but have it actually consider all #’s at the beginning of the title and sort by street name instead (for example 1001 Main St), but also sort ASC?

  84. I’m not sure the posts_orderby filter works with custom posts. I’m about to go to bed now and I won’t be back on-line until after the 1st of January. Will send you an email then. Happy holidays!

  85. Perhaps you could google MySQL regexp. Fact is I’m about to go to bed now and I won’t be back on-line until after the 1st of January. Will send you an email then. Happy holidays!

  86. Thank you so much for your response. Ill google as suggested – that might be just enough info to get me there. Ive been searching for over a week now with various keywords, including regex…but hopefully regexp will help. Ill let you know if I have success. Until then, enjoy the holidays!

Comentariile sunt închise.