WordPress.org

Ready to get started?Download WordPress

Forums

How to sort Posts (or Pages) by title while in admin panel (13 posts)

  1. peacesong
    Member
    Posted 4 years ago #

    Hi,

    I'm using WP as a CSM - my largest site every with dozens and dozens of posts, eventually a few thousand.

    How can I sort my existing posts by something other than categories?

    Eg, by Title, date or a combination of categories? I want to do this in the admin panel but can not find a plug in...

    Trying to find an existing entry without sorting criteria is incredibly time consuming.

    Thank you for feedback/direction!

    Peacesong

  2. MichaelH
    Member
    Posted 4 years ago #

    Aren't pages already in title order with children under their parents?

    I thought there was a plugin for this, but couldn't find it:

    <?php
    /*
    Plugin Name: Set Post Order In Admin
    Version: 0.1
    Plugin URI: http://wordpress.org/support/topic/336715/
    Description: In Posts->Edit, display posts in title order.
    Author: MichaelH
    Author URI: http://codex.wordpress.org/User:MichaelH/MyPlugins
    */
    
    function set_post_order_in_admin( $wp_query ) {
      if ( is_admin() ) {
        $wp_query->set( 'orderby', 'title' );
        $wp_query->set( 'order', 'ASC' );
      }
    }
    add_filter('pre_get_posts', 'set_post_order_in_admin' );
    ?>

    Save that as set_post_order_in_admin.php in your wp-content/plugins folder.

  3. jcowdrey
    Member
    Posted 4 years ago #

    Will this work for pages too?

    I've been searching for a way to order the pages in admin by date modified.

  4. designfollow
    Member
    Posted 4 years ago #

    I benefited from this debate
    Thank you all

  5. JamesBB
    Member
    Posted 4 years ago #

    Hi !

    jcowdrey said "I've been searching for a way to order the pages in admin by date modified."
    and so am I ! :-)
    If anyone has got an idea, pls post here.

    THANK YOU !

    Jamy

  6. pdonnelly
    Member
    Posted 4 years ago #

    Thanks MichaelH for the plugin!
    Is it easy to mod? I'm using write panels and only want to sort one category tilted reports.

    Thanks again.

  7. pdonnelly
    Member
    Posted 4 years ago #

    guess its to hard :( can't figure it out myself. Thanks anyway.

  8. jteg
    Member
    Posted 4 years ago #

    pdonnelly: I had the same problem and found a working solution.

    I am using Magic Fields and have three different Write panels, for three categories of posts. Two of them I wanted to order alphabetically (Artists and Discography) and the other (News) I wanted chronologically.

    Here's the code:

    function set_post_order_in_admin( $wp_query ) {
    $customwrite = strstr(curPageURL(), 'custom-write-panel-id=');
    $admincatid = substr($customwrite, 22);  								
    
      if ( is_admin() AND $admincatid != '3') {
        $wp_query->set( 'orderby', 'title' );
        $wp_query->set( 'order', 'ASC' );
    
      }
    }
    add_filter('pre_get_posts', 'set_post_order_in_admin' );

    Magic Fields adds "custom-write-panel-id=1" to the end of the URL to define which custom write panel the administrator is currently editing. So this code checks the current URL with "curPageURL()" and then strips the URL string from everything before "custom-write-panel-id=" with the php function strstr.

    Now the variable $customwrite is "custom-write-panel-id=3". And then I strip this variable from the 22 first characters, leaving only the number. And then I check so that the plugin only order by title as long as the custom-write-panel-id is NOT equal to 3 ($admincatid != '3'), which is the number for News.

  9. Ian
    Member
    Posted 4 years ago #

    Worked for me! thank you!

  10. semrocc
    Member
    Posted 3 years ago #

    This is very close to what I am looking for. The only change is that I need to sort posts in the admin panel by expiration date. I'm using the post-expirator plugin which creates a meta key "expiration-date".

    How would I modify the code below to sort using the meta_key value?

    $wp_query->set( 'orderby', 'title' );

    Any help would be appreciated!

  11. semrocc
    Member
    Posted 3 years ago #

    Can anyone help on this...?

  12. moi3ius
    Member
    Posted 3 years ago #

    Try something like this:

    $wp_query->set( 'orderby', 'meta_value' );
    $wp_query->set( 'meta_key', '[your meta key]' );
  13. semrocc
    Member
    Posted 3 years ago #

    Thanks very much...that worked perfect :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.