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)?