Support » How-To and Troubleshooting » sorting posts by post type or any other variable..

sorting posts by post type or any other variable..

  • I have 3 custom post type (a, b, c) and one custom taxonomy. I want display (in this taxonomy archive page) my posts by order: first posts “a”, next posts “b” and then posts “c”. Now (default) my custom posts (a, b and c) are order by date.
    Maybe it is possible ordering posts by CPT slug or by any other variable (custom post field)?
    Maybe is it plugin where i can tape order number next to CPT name f.e.:
    CPT order
    post -2-
    book -1-
    my_another_custom_post_type -3-

    If you know some plugin..
    I am searching since 2 week, and I’am losing my hope..
    Please, help 🙂
    sorry for my english..

Viewing 1 replies (of 1 total)
  • You should be able to do this using a filter. The exact code depends on the way your query is written. If you post a few lines from your template, including the query, I will try to show you the exact code.

    In general, you would add the following just before the query:

    function mam_posts_orderby ($orderby) {
       global $mam_global_orderby;
       if ($mam_global_orderby) $orderby = $mam_global_orderby;
       return $orderby;
    $mam_global_orderby = " $wpdb->posts.post_type ASC, $wpdb->posts.post_date DESC ";

    and add this line after the query to clear the filter:

    $mam_global_orderby = '';
Viewing 1 replies (of 1 total)
  • The topic ‘sorting posts by post type or any other variable..’ is closed to new replies.