WordPress.org

Ready to get started?Download WordPress

Forums

Post Types Order
[resolved] autosort replaces existing order of all post queries (4 posts)

  1. wizdum
    Member
    Posted 1 year ago #

    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/

  2. nsp-code
    Member
    Plugin Author

    Posted 1 year ago #

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

  3. gavin27
    Member
    Posted 1 year ago #

    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...

  4. OuchMyAppendix
    Member
    Posted 1 year ago #

    @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!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.