How sort products by calculate value? ( custom post meta, price, option)

Firstly i added table postmeta to query function add_join_clause_to_view_sql( $join, $wpq ) { global $wpdb; if( $wpq->query[‘orderby’] === ‘price’ || $wpq->query[‘orderby’] === ‘price-desc’) { $post_meta_table_name = $wpdb->postmeta; $post_table_name = $wpdb->posts; $join .= ” LEFT JOIN $post_meta_table_name ON $post_meta_table_name.post_id = $post_table_name.id “; } return $join; } add_filter(‘posts_join’, ‘add_join_clause_to_view_sql’, 10, 2); Secondly i added meta_key in WHERE … Read more

WordPress Meta Query Null Values Order

Generally, no, there is not a good way to achieve this if the sort order doesn’t produce things automatically in the order you need them. This is because WP_Query doesn’t allow for insertion of logic to say ‘order by fieldX except if $some_condition’ Somewhere, you’re going to have to write the logic for the order … Read more

Custom WP Query order function possible?

No, it’s not possible. You can’t actually store arrays as meta. When they’re saved they’re converted to a string, so there aren’t individual parts that you can sort by. To do this you will need to store the share numbers as their own keys.