Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Lyubomir Gardev

    (@rolice)

    Yes, this makes sense. I will add such feature in next release.

    Thank you!

    Thread Starter 3×7

    (@3x7)

    u’re welcome!

    it would be even greater if it would offer a widget that on the backend admins could select the one or more custom fields to include for sorting, and on the frontend user could select the way of sorting by selected custom field…

    Good lightweight plugin anyway!

    Plugin Author Lyubomir Gardev

    (@rolice)

    The front-end control of sorting will be included in further releases.
    In order to make it extensive and applicable I had added SQL statements where the user could design its own sorting, since the tables and columns for sorting may vary. By default, WordPress does not have rating, as far as I know, so with each rating plugin the mechanism will also vary. This way it will be plugin independent.

    From programming view point it will have two filters:

    1. post_sorter_join
    2. post_sorter_order

    Where the filters would accept the current SQL where if they want they could modify it directly, for example from another plugin.

    However, I need to perform additional tests and to inspect a problem with gallery/media which have been reported, before I put the new version.

    Thread Starter 3×7

    (@3x7)

    perfect… I’ll be waiting for the update… take you time.

    Cheers!

    Plugin Author Lyubomir Gardev

    (@rolice)

    The new features are added. With them custom sorting you should be able to make complex sorting. However, it requires SQL knowledge and it will also disable the sorting by the position factor, since the value would not be taken from there.

    Thread Starter 3×7

    (@3x7)

    Great!

    Would you briefly explain how to make it sort by custom field “price”

    Thanks!

    Plugin Author Lyubomir Gardev

    (@rolice)

    Is it going postmeta?

    Thread Starter 3×7

    (@3x7)

    yes

    Plugin Author Lyubomir Gardev

    (@rolice)

    Sorry, I was away for some time, since I broke the SVN repo and I had to fix it. Now it is ok.

    So..

    Now you have two option from plugin or theme of yours you could attach to filters mentioned above or to use the two fields in the settings. In both cases your hook or text in the textareas should be something like:

    JOIN Clause:
    LEFT JOIN wp_postmeta AS post_sorter ON (wp_posts.ID = post_sorter.post_id AND post_sorter.meta_key = 'price')

    ORDER BY Clause (ASCending or DESCending):
    CAST(post_sorter.meta_value AS DECIMAL(12,2)) ASC

    PS: Tell me if it worked out.

    Thread Starter 3×7

    (@3x7)

    no luck, they are sorted the same way.
    every time after saving settings I get one more “backslash” before and after \\\’price\\\’

    however, is there a way to make and widget which would have options like, sort by “Price” – ASC/DESC, sort by “discount” etc?

    thanks.

    Plugin Author Lyubomir Gardev

    (@rolice)

    Hello, this escaping with backslash now should be fixed, please verify with the same code.

    The problem with such custom fields is that the plugin does not know about them (any possiblity may vary) and does not know how to treat them (as integer number, decimal, money, text, etc., since in database they are all texts) that is why I have left this big text boxes.

    I have an idea how to make it works for post metadata, but it will require a new release with additional functionality, where you could have a lists of postmeta keys the user wants and the cast for each one which is required – how the plugin should treat them as number, monetary or alphabetically.

    Actually it is possible to make such widget with these filters.

    Example:

    add_filter( 'post_sorter_join', 'my_price_join' );
    add_filter( 'post_sorter_order', 'my_price_order' );
    
    function my_price_join( $sql ) {
       $join = "LEFT JOIN wp_postmeta AS post_sorter ON (wp_posts.ID = post_sorter.post_id AND post_sorter.meta_key = 'price')";
    
       return $join . $sql;
    }
    
    function my_order_join( $sql ) {
       $orderby = "CAST(post_sorter.meta_value AS DECIMAL(12,2)) ASC";
    
       return $orderby . ( $sql ? ', ' . $sql : '' );
    }

    You could join them both (2 joins) with discount and order by both or some formula. You could take the sorting direction by external code and instead of ASC or DESC you can put that variable, for example, sorting direction retrieval from the plugin:

    $direction = mb_strtoupper( get_option( 'post_sorter_direction' ) ) == 'DESC' ? ' DESC' : '';
    ...
    $orderby = "CAST(post_sorter.meta_value AS DECIMAL(12,2)) $direction";

    Unfortunately, there is no front-end interface (widgets and so on) for controlling the sorting, but it could be implemented on this base.

    Please check with v1.3.1 and tell me if it is sorting by price correctly (with the previous two codes for join and order)?

    Thread Starter 3×7

    (@3x7)

    I tried with the new version, still no luck, but as you said it does not know what type the value is it. I believe the problem is simply the format, since there is “.” in the number.
    I had been playing with this before and it worked if the number was only value (1255 instead of 12.55).
    I’ll see if I could generate another custom field with converted values or something.

    I’ll also try to create a widget, but not sure if I could do it myself.

    I really appreciate your effort.

    Thank you again.

    Cheers!

    Plugin Author Lyubomir Gardev

    (@rolice)

    I will continue work in this direction. Let me know if you have any questions up to then. You could open new support topic where we could discuss problems targeted at this custom sorting.

    Thanks, @3×7

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Automatic position based on popularity or custom field?’ is closed to new replies.