• I have been stuck for a few hours on this problem and would love any suggestions on how to do this.

    I have post meta field that is a checkbox with the name and value “featured”.

    I need to order posts that have been modified or created in the last 24 hours and also have the post meta field “featured” first followed by the rest of the posts.

    I have tried using the pre_get_posts filter but with no luck.

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Here is some sample code that I believe will do what you want:

    https://pastebin.com/p5mv7625

    Note that it sorts on the date published. If you want to sort on date modified, change this line:

    $mam_global_orderby = "sort_key, $wpdb->posts.post_date DESC";

    to this:

    $mam_global_orderby = "sort_key, $wpdb->posts.post_modified DESC";
    Thread Starter Colin Murphy

    (@colin-murphy)

    Thanks very much. That worked perfectly ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Query for Sorting Post by Post Meta Fields’ is closed to new replies.