WordPress.org

Support

Support » Plugins and Hacks » [Resolved] [Plugin: Post Types Order] autosort replaces existing order of all post queries

[Resolved] [Plugin: Post Types Order] autosort replaces existing order of all post queries

  • I had a theme feature that displayed popular posts by querying posts ordered by comment_count.

    Posts Types Order filters orderby in
    function CPTOrderPosts($orderBy)

    and replaces orderby:-

    $orderBy = "{$wpdb->posts}.menu_order, {$wpdb->posts}.post_date DESC";

    suggestion: change this to

    $orderBy = "{$wpdb->posts}.menu_order, " . $orderBy;

    this adds your menu_order as primary ordering and leaves the existing orderby intact.

    http://wordpress.org/extend/plugins/post-types-order/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author nsp-code

    @nsp-code

    That’s an excellent suggestion, thanks for the tip, we will include this in the next version.

    hey sry I have this prob can you help me solve this I know very little thanks filmscope.net

    IS IT THIS THAT i EDIT?

    function CPTOrderPosts($orderBy)
    {
    global $wpdb;

    $options = get_option(‘cpto_options’);

    if (is_admin())
    {
    if ($options[‘adminsort’] == “1”)
    $orderBy = “{$wpdb->posts}.menu_order, {$wpdb->posts}.post_date DESC”;
    }
    else
    {
    if ($options[‘autosort’] == “1”)
    $orderBy = “{$wpdb->posts}.menu_order, {$wpdb->posts}.post_date DESC”;
    }

    return($orderBy);

    your help[ will be appreciated…

    @gavin27 : Here is the whole function to copy/paste. Original line is commented out and the modification is present.

    function CPTOrderPosts($orderBy)
        {
            global $wpdb;
    
            $options = get_option('cpto_options');
    
            if (is_admin())
                    {
                        if ($options['adminsort'] == "1")
                            $orderBy = "{$wpdb->posts}.menu_order, {$wpdb->posts}.post_date DESC";
                    }
                else
                    {
                        if ($options['autosort'] == "1")
                        	// Here is where the edit goes
                        	$orderBy = "{$wpdb->posts}.menu_order, " . $orderBy;
                            //original code is commented out
                            //$orderBy = "{$wpdb->posts}.menu_order, {$wpdb->posts}.post_date DESC";
                    }
    
            return($orderBy);
        }

    @op – Thanks so much for this, I was having an issue with this plugin changing the order of attachments on my page and this fixed it. Kudos!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] [Plugin: Post Types Order] autosort replaces existing order of all post queries’ is closed to new replies.