Post Mash Filtered

June 19, 2009 at 7:25 pm 27 comments

postMash Filtered is a simple tweak of another WordPress plugin written by Joel Starnes, postMash. However, the admin panel has been modified to allow you to filter posts by Category and Date, before you reorder them. Previously, you could only reorder from a list of all the posts in your sites blog.

I have also added a function to allow you to use WordPresses inherent ‘Next Post Link’ ‘Previous Post Link’ calls, but call by the new menu order, not by date, so that when your template is reconfigured (using the instructions below) to list all posts by your new, custom order, the ‘Next Post Links’ and ‘Previous Post Links’ will match this order. Please read instructions for using this below.

Details of postMash

Posts are usually listed in reverse chronological order as they are often used for posting regular time-orientated content, however if you want to choose the order they appear in, then this is the plugin for you.
Usage

To make use of this chosen order you will need to modify your template code:
Open wp-content/themes/your-theme-name/index.php and find the beginning of ‘the loop’. Which will start:

if(have_posts())

Then add the following code directly before this:

<?php
$wp_query->set(‘orderby’, ‘menu_order’);
$wp_query->set(‘order’, ‘ASC’);
$wp_query->get_posts();
?>

This just tells WP to get the posts ordered according to their ‘menu_order’ position. Therefore you can get the posts ordered anytime you use a function such as get_posts simply by giving it the required arguments:

<?php get_posts(‘orderby=menu_order&order=ASC’); ?>

Checkout the get_posts() function in the wordpress codex for more info.
Note that it says menu_order is only useful for pages, posts have a menu_order position too, it just isn’t used. postMash provides you with an iterface so that you can use it.

Next/Previous Links

to call the next and previous links in the same order as your new post order, in your templates ‘single.php’ use the following commands, in place of the original ‘next_post_link()’ and ”previous_post_link()’ (all other variables work the same within this function);

next_post_link_menu()

previous_post_link_menu()

Admin Panel Post Order

To view posts in the same order as postMash in the regular admin panel, edit wp-admin/includes/post.php at line 794 to look like;

if ( isset($q[‘post_status’]) && ‘pending’ === $q[‘post_status’] ) {
$order = ‘ASC’;
$orderby = ‘menu_order’;
} elseif ( isset($q[‘post_status’]) && ‘draft’ === $q[‘post_status’] ) {
$order = ‘ASC’;
$orderby = ‘menu_order’;
} else {
$order = ‘ASC’;
$orderby = ‘menu_order’;
}

Download Plugin

Entry filed under: Uncategorized.

WordPress Plugin Blog

27 Comments Add your own

  • 1. Joseph Condron  |  July 4, 2009 at 9:23 pm

    Hi Joel,

    I am delighted that you have created this plugin as I want to place posts in alphabetical order. I feel that you are addressing a key area that was lacking.

    However, I am very green when it comes to websites and blogging and I can not get the site to publish the posts in my desired order.

    These are my humble attempts at altering the code. I was hoping could you tell me what I am doing wrong?

    set(‘orderby’, ‘menu_order’);
    $wp-query->set(‘order’, ‘ASC’);
    $wp-query->get_posts();
    ?>if (have_posts()) : ?>

    Regards Joseph.

    Reply
  • 2. Laura  |  July 13, 2009 at 3:53 am

    Hi, I’m trying (unsuccessfully) to get PostMash to work in teh pageofposts templates.

    Any ideas? Here is the code of the pageofpost.php Many thanks!

    $cat,
    ‘showposts’ => $showposts,
    ‘caller_get_posts’ => $do_not_show_stickies,
    );
    $my_query = new WP_Query($args);
    ?>

    have_posts() ) : ?>

    have_posts()) : $my_query->the_post(); ?>

    in_the_loop = true;
    ?>

    post_excerpt ) ) :
    the_excerpt();
    else :
    false;
    endif; ?>

    Not Found
    Sorry, but you are looking for something that isn’t here.

    Reply
  • 4. Corey  |  July 14, 2009 at 3:09 am

    I moved my blog from my computer’s server to a real server and now I get “Error: Update Timeout”. I was wonder if you could help me track down exactly why it can’t update the database. I have the latest version of your plugin and WordPress 2.8.1.

    Also, by way of a feature request, could you add the ability to set a default category for postMash to open with? When postMash is clicked, I’d like it to go straight to my Feature category.

    Kudos on a great plugin by the way. When it worked on my comptuer’s server, it was by far the simplest solution out there.

    Reply
  • 5. Joey  |  July 15, 2009 at 2:12 am

    I have added this plugin to my site and I added the code before if(have_posts()) but it is not working. I’m not sure what you mean by giving it the required argument?

    Reply
  • 6. Albert  |  July 15, 2009 at 4:11 pm

    Hi There

    I use WordPress as a CMS. Therefore this plugin is ideal for me. Only problem is I’m not getting it to work.

    I copied this code in the index.php file like you explained:
    set(’orderby’, ‘menu_order’);
    $wp_query->set(’order’, ‘ASC’);
    $wp_query->get_posts();
    ?>

    Then you mention this code:

    What should I do with that?

    Kind regards,
    Albert

    Reply
  • 7. Brent Lagerman  |  July 24, 2009 at 5:24 am

    This plugin is exactly what I was looking for, implimented in a very graceful way as well 😀 Thanks for sharing it.

    brent
    @
    mimoYmima.com

    Reply
  • 8. Josh  |  July 29, 2009 at 6:08 pm

    Awesome plugin. I did some hackin’ to add an additional filter for tags. In order to do this, I modded a custom query I found on the wordpress site and used this query to replace the query provided in the plugin. Anyway, the tag list is simply hardcoded for my purposes now, although it would be nice for an option to be saved where a user can store a list of tags s/he wants to order or simply have their entire tag list present to filter by. Finally for to facilitate things for my editor I placed a copy of the Update button on top of the post list and pushed it to the left margin. I haven’t tested this extensively, but I do think it’s a good foundation for an update to this plugin. The tag list and button copy is simple HTML, so here’s just the modded query.


    //Query modded from beatpanda's http://wordpress.org/support/topic/268128
    $query_post .= "SELECT DISTINCT p.* from $wpdb->posts p, $wpdb->terms t, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t2, $wpdb->term_taxonomy tt2, $wpdb->term_relationships tr2 WHERE p.id = tr.object_id AND t.term_id = tt.term_id AND tr.term_taxonomy_id = tt.term_taxonomy_id AND p.id = tr2.object_id AND t2.term_id = tt2.term_id AND tr2.term_taxonomy_id = tt2.term_taxonomy_id";

    if (isset($_GET['cat']) && $_GET['cat'] != '0'){
    $query_post .= " AND (tt.taxonomy = 'category' AND tt.term_id = t.term_id AND tt.term_id = ".$_GET['cat'] .")" ;
    }

    if (isset($_GET['tag']) && $_GET['tag'] != '0'){
    $query_post .= " AND (tt2.taxonomy = 'post_tag' AND tt2.term_id = t2.term_id AND t2.slug = '". $_GET['tag'] ."')" ;
    }

    if (isset($_GET['m']) && $_GET['m'] != '0' ) {
    $query_post .= " AND YEAR(p.post_date) = " . $yyear ." AND MONTH(p.post_date) = " . $mmonth ;
    }

    $query_post .= " AND p.post_type = 'post' ORDER BY menu_order ";

    $pageposts = $wpdb->get_results("$query_post");

    Reply
  • 9. Kenny  |  August 18, 2009 at 12:00 am

    love this. thank you so much!!

    I used it on my portfolio site to order the posts how I wanted them instead of by date.

    I used it in archive.php, not index.php, so I could use category listings, but it’s the same code.

    Plug-in works like a charm as long as you put the code in your core files.

    Reply
  • 10. Rodrigo  |  August 20, 2009 at 2:34 pm

    Are you thinking about a plugin upgrade that works with tags too, the same way it works with categories?

    Reply
  • 11. Plugins | The Grand Adventures of Daisy Donnie  |  September 4, 2009 at 9:51 am

    […] postMash (Filter) – puts the posts into a particular order. Helps with the mobile version so the posts appear in the right way. […]

    Reply
  • 12. James  |  September 7, 2009 at 3:30 pm

    is the only change required in the template
    set(’orderby’, ‘menu_order’);
    $wp_query->set(’order’, ‘ASC’);
    $wp_query->get_posts();
    ?>

    Or is the second line of code

    needed in a specific template as well?

    I have it setup however the ordering isn’t working in categories just the main page/

    Reply
  • 13. Bob  |  September 17, 2009 at 4:42 pm

    any way to make it toggle to archive instead of draft.

    Though i can see changing to menu instead of date could make that difficult

    Great job by the way. Your instructions worked great.

    Reply
  • 14. Dan  |  October 7, 2009 at 1:24 am

    Just what I was looking for, works perfectly, thanks!

    Reply
  • 15. Rich Hamilton  |  October 20, 2009 at 3:14 pm

    I love postMash and I love the filtered access… thought you might be interested in this little addition to the plugin code.

    This automatically makes Category Pages order by the postMash list.


    function postmashx_reorder($qarray) {
    if (is_category() && function_exists('postMash_main'))
    $qarray->query_vars=array_merge( (array)$qarray->query_vars, array('orderby' => 'menu_order', 'order' => 'ASC') );
    }
    add_action('parse_query','postmashx_reorder');

    Reply
  • 16. bryan fusilier  |  November 8, 2009 at 8:42 pm

    Hi there,
    I’m having problems getting this plug in to work. It installs fine and I can move things around in the admin side, but my posts are not being reordered.

    Firstly I’m very new to wordpress, so I’ll ask a dumb question. I should be able to see the newly sorted order when I visit an archive of a category correct? If not, then that’s where I’m looking to see the reorder.

    I’ve put the code in the template like your page outlined. However, I’m not sure where this code goes. Right now, I just posted it after the other code. I’m probably missing something here.

    Any suggestions?

    B

    Reply
  • 17. Jason  |  November 10, 2009 at 12:49 pm

    Hey there. The filtering is awesome. Thanks a lot. Any ambitions to add a filter group for Tag?

    Reply
  • 18. Dainis W. Michel  |  November 18, 2009 at 9:45 pm

    Pretty cool man, my page.php has

    …not sure what to replace, should it be:

    set(‘orderby’, ‘menu_order’);
    $wp_query->set(‘order’, ‘ASC’);
    $wp_query->get_posts();
    ?>

    …don’t want to goof with this, but it’d be great to get this to work.

    Cheers from Vienna!
    –Dainis

    Reply
  • 19. Dainis W. Michel  |  November 18, 2009 at 9:46 pm

    whoops, my comment isn’t showing code as code…hope the text of the code came through…

    Reply
  • 20. TarmoS  |  November 25, 2009 at 12:03 pm

    Very useful plugin. I use it to reorder products in e-shop. Thanks a lot for your work. 🙂

    Will Post Mash Filtered be compatible with WP 2.9?

    Reply
  • 21. Sahar  |  December 9, 2009 at 3:29 pm

    Hi there, looks like very nice modification, can you please tell on what version of postMash, postMash (filtered) is based on ?

    I’m asking because postMash 1.2.0 offers great new improvement – no need to edit the template code.

    Thanks,
    Sahar

    Reply
  • 22. knokenet  |  December 31, 2009 at 6:08 pm

    Hello!

    Great plugin!
    I have a small problem, maybe you can help:
    For some reason all the posts on the post-mash page appear from the first post at the top, and the last post at the bottom, so every new post goes straight into being the last post.
    How can I reverse the order in one go?

    Thanks!

    Knokenet

    Reply
  • 23. LydiaG  |  January 2, 2010 at 5:26 am

    I have used the original postmash successfully but really struggle with this. When I go to the panel to use your one there was a link for more information and I put that where I thought it should go in the single post php. I now see that there is a lot more to tweak. My thinking is that I will go back to using the original.

    Reply
  • 24. Mark  |  January 10, 2010 at 6:58 pm

    Neat tweak, just what I needed. And everything works as expected. Thanks!

    Reply
  • 25. Scott Cromwell  |  January 13, 2010 at 1:12 am

    I just found and downloaded your Post Mash Filtered plugin and it works like a charm. This was exactly what I was looking for. You have just save me a TON of labor-intensive work, no doubt! I couldn’t be more pleased. Thank you very much!

    Scott
    OnlineHowTo.com

    Reply
  • 26. TarmoS  |  January 13, 2010 at 9:58 am

    Is it possible to make Post Mash Filtered work with WPML (best multilingual content plugin for WordPress in my opinion)? Right now posts in different languages are mixed.

    Would be great. 🙂

    Reply
  • 27. Mark  |  January 15, 2010 at 10:04 pm

    It looks like the posts in the feed are not reordered. Is that correct? And if so, how do I change that?

    Reply

Leave a reply to TarmoS Cancel reply

Trackback this post  |  Subscribe to the comments via RSS Feed


My Other Blog