WordPress.org

Support

Support » Plugins and Hacks » [Plugin: PostMash Custom – custom post order] improvement to plugin

[Plugin: PostMash Custom – custom post order] improvement to plugin

  • the initial view of the posts is in the wrong order the first time you use the plugin because there are no values in menu_order. A solution to this would be to order the posts by date as the first variable, then by menu_order. Once you save the menu_order will always be dominant. LIke so.

    ORDER BY post_date DESC, menu_order ASC”

    hope this helps.

    here is the new if statement:

    foreach($res as $r) {
    		$psql .= " $sep post_type ='$r' ";
    		$sep = "OR";
    	}
    	$psql = "($psql)";
    
    	// use this if you just want posts
    	//$psql = " post_type = 'post' ";
    
    	$date = $_GET['m'];
    	$mmonth = substr($date, -2);
    	$yyear = substr($date, 0, 4); 
    
    	//get posts from database
    	$query_post .= "SELECT * FROM $wpdb->posts ";
    
    	if (isset($_GET['cat']) && $_GET['cat'] != '0') {
    		$query_post .=	"INNER JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    						 INNER JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    						 WHERE $wpdb->term_taxonomy.term_id = " . $_GET['cat'] ;
    		$query_post .=	" AND $psql";
    	} else {
    		$query_post .= "WHERE $psql ";
    	}
    
    	if (isset($_GET['m']) && $_GET['m'] != '0') {
    		$query_post .= " AND YEAR($wpdb->posts.post_date) = " . $yyear ." AND MONTH($wpdb->posts.post_date) = " . $mmonth ;
    	}	
    
    	$query_post .= " AND post_status = 'publish'";
    	$query_post .= " ORDER BY post_date DESC, menu_order ASC" ;

    http://wordpress.org/extend/plugins/postmash-custom/

Viewing 4 replies - 1 through 4 (of 4 total)
  • The last line should have the arguments reversed

    ORDER BY menu_order ASC, post_date DESC"

    and then in the template you’ll need to put order=ASC in addition to orderby=menu_order. Or for example:
    <?php query_posts( array( 'orderby'=>'menu_order', 'order'=>'ASC' ) ); ?>

    Plugin Author torsteino
    Member

    @torsteino

    Nice touch Dwenaus, thanks! Will implement this in the next update 🙂

    Michelle
    Participant

    @mmcginnis

    This didn’t make it in the latest update I take it? I’m still seeing newest posts at the bottom of the list in the admin when I first go to re-order.

    I tried to update the code myself using the above but it doesn’t work with the latest version of the plugin. 🙁 Would LOVE this feature -thanks so much!

    Michelle
    Participant

    @mmcginnis

    I think I have it fixed:

    Changed line 117 from $query_post .= ” ORDER BY menu_order ” ;} to $query_post .= ” ORDER BY menu_order ASC, post_date DESC ” ;}

    Changed line 292 from post_date DESC to post_date ASC

    Not sure why those changes were needed but it seems to work now. Whew! Thanks,
    Michelle

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: PostMash Custom – custom post order] improvement to plugin’ is closed to new replies.