Sort post by "Weight"

  1. gleenk


    Why not giving the possibility to sort post (using a drag and drop interface) by weight? Maybe "imitating" drupal weight module? http://drupal.org/project/weight

    Posted: 6 years ago #
  2. Mark Root-Wiley


    Having used the Drupal feature, I have a hard time seeing how this would really work. Posts are inherently supposed to be date-ordered as they're time-sensitive content. Pages and other custom post types support the "menu order field" which can essentially do what you're asking, and posts even support "stickiness" which covers most situations where you need to change the order.

    Maybe I'm just not understanding the scenario you have in mind right, but this just seems to muddle the purpose of posts.

    Posted: 6 years ago #
  3. BlueDot

    Yes, many people use wordpress as much more than a simple date based blog.

    Think outside the box... and I have a client right now wanting to weight posts such as Drupal.

    Posted: 6 years ago #
  4. gleenk


    Menu order-field is not enough. The problem infact rest the post-date idea. When creating a post-type I should be able to decide if this have a date or other kind of sorting.

    Posted: 5 years ago #
  5. Ipstenu (Mika Epstein)

    By default, the order of things is the order of things. If you make your CPT with custom fields for weight, then you can design your archive page for that CPT to use that weight.

    Posted: 5 years ago #
  6. mbrown1029

    I have found many situations where I wished I could weight my posts as I have in Drupal or change the general sort order. One instance was when a client wanted their info sorted alphabetically. Right now I am struggling with my portfolio because I want to reorder the posts without having to delete and recreate because I want certain projects to have more importance. Very frustrating not to have that control.

    Posted: 5 years ago #
  7. Akexis

    Even though this is many years later, I decided to respond in case others need this info. (I'm constantly looking on Google for this answer because I forget specific syntax. This thread came up as top result for my search.)

    You have to create a new query in your template file. Specific info can be found here: https://codex.wordpress.org/Class_Reference/WP_Query

    $newQuery = new WP_Query(
            'post_type' => 'post',
            'orderby'   => 'menu_order',
            'order'		=> 'ASC',
            'posts_per_page' => -1

    You can change order to DESC if you need it to go the other direction in your ordering. Then in place of the standard loop, you modify it a little:

    <?php while ( $newQuery->have_posts() ) : $newQuery->the_post(); ?>

    Don't forget to reset your query so you don't run into weird issues in other places on your site! Add this after your loop.

    <?php wp_reset_query(); ?>

    If this is for a custom post type, you'll need to make sure you add page-attributes support to your post type.

    If it's for regular posts, you'll need to add page-attributes support in your functions file.

    function wpcodex_add_menu_order_for_posts() {
        add_post_type_support( 'post', 'page-attributes' );
    add_action( 'init', 'wpcodex_add_menu_order_for_posts' );

    Then from there you can edit the Order box in the Attributes section on the right in your posts. They all default to 0, so if you don't change the numbering, it'll default to the 'order' parameter and pull in your posts in ascending or descending order, depending on how you pulled that in your query.

    This isn't an in depth guide, so don't treat it as such, more just a quick reference.

    Posted: 2 years ago #
  8. ssdesmet

    Would be great, just like what Ipstenu sais: the order of things is the order of things.
    My idea is to use it only in Custom Post types and maybe taxonomies.

    Posted: 2 years ago #
  9. Pragna

    Hi Gleenk,

    There is a useful module to re-order the Posts.

    Posted: 2 years ago #
  10. They should definitely consider adding this feature by default.

    Posted: 2 years ago #

RSS feed for this topic

Reply »

You must log in to post.

  • Rating

    7 Votes
  • Status

    This is plugin territory