Support » How-To and Troubleshooting » [Resolved] Sort on size

[Resolved] Sort on size

  • I have a meta custom field “x” and a meta custom field “y”.

    I want to build a page that shows posts sorted on size.

    I can do this on the “x” (by using ‘meta_key’=>x and ‘orderby’=>x)

    But how can i order it on x*y (AND sorting on the numeric value and not the text value) do I need to pre process it first?

Viewing 3 replies - 1 through 3 (of 3 total)
  • You do not need to pre-process, but you will need to use filters. Here is some sample code to get you started:

    function mam_posts_join ($join) {
       global $mam_global_join;
       if ($mam_global_join) $join .= " $mam_global_join";
       return $join;
    function mam_posts_orderby ($orderby) {
       global $mam_global_orderby;
       if ($mam_global_orderby) $orderby = $mam_global_orderby;
       return $orderby;
    $mam_global_join = "JOIN $wpdb->postmeta metax ON (metax.post_id = $wpdb->posts.ID AND metax.meta_key = 'x')
       JOIN $wpdb->postmeta metay ON (metay.post_id = $wpdb->posts.ID AND metay.meta_key = 'y')";
    $mam_global_orderby = " metax.meta_value * metay.meta_value ASC";


    You are welcome! Now, please use the dropdown at top right to mark this topic ‘Resolved’.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Sort on size’ is closed to new replies.