ColorlibHQ / simple-custom-post-order

Order posts(posts, any custom post types) using a Drag and Drop Sortable JavaScript. Configuration is unnecessary.
http://wordpress.org/plugins/simple-custom-post-order/
GNU General Public License v3.0
31 stars 19 forks source link

Order not working on taxonomy archive #70

Open mplusb opened 4 years ago

mplusb commented 4 years ago

https://wordpress.org/support/topic/order-not-working-on-taxonomy-archive/

razvanaldea89 commented 4 years ago

Tested with Twenty Nineteen, Twenty Twenty and Twenty Seventeen themes and works. Did the custom posts types and taxonomies the user suggested but again, the order works on archive.php and taxonomy-region.php .

Also, checking the “Show advanced view of Post Types” will show other hidden post types/taxonomies ( see screenshot bellow ) in the lists.

Option toggled off : Screenshot_2020-04-21 SCPOrder ‹ Colorlib plugins — WordPress

Option toggled on: Screenshot_2020-04-21 SCPOrder ‹ Colorlib plugins — WordPress(1)

In 2nd screen blocks post can be seen while in the first screen is not there.

JoshuaCrewe commented 4 years ago

Just so I can write it somewhere, I found this issue through https://wordpress.org/support/topic/order-not-working-on-taxonomy-archive/.

I was experiencing the same issue that the OP there was.

I tried deactivating some plugins, including this one. When I turned them back on again I got an error from this plugin :

[30-Apr-2020 16:13:10 UTC] PHP Notice:  Trying to get property 'cnt' of non-object in /var/www/project/public/content/plugins/simple-custom-post-order/simple-custom-post-order.php on line 279
[30-Apr-2020 16:13:10 UTC] WordPress database error Unknown column 'term_order' in 'field list' for query
                    SELECT count(*) as cnt, max(term_order) as max, min(term_order) as min
                    FROM vpwp_terms AS terms
                    INNER JOIN vpwp_term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
                    WHERE term_taxonomy.taxonomy = 'department'
                 made by do_action('admin_init'), WP_Hook->do_action, WP_Hook->apply_filters, SCPO_Engine->refresh
[30-Apr-2020 16:13:10 UTC] PHP Notice:  Undefined offset: 0 in /var/www/project/public/content/plugins/simple-custom-post-order/simple-custom-post-order.php on line 279

I went to the plugin settings, turned everything off. Then turned on the CPT I was using it for. The error has gone away but it still isn't ordering on category pages.

I can force it to using the pre_get_posts work around :

function custom_pre_get_posts($wp_query) {
    if (($wp_query->is_main_query()) && (is_tax([ ... taxonomies ... ]))) {
        $wp_query->set('orderby', 'menu_order');
        $wp_query->set('order', 'ASC');
    }
}

add_action('pre_get_posts', 'custom_pre_get_posts');

Maybe this is enough :)

Blindeman commented 3 years ago

I'm having the same problem as OP. With theme twenty twenty-one and only the plugin that adds the CPT and custom taxonomy enabled, plus SCPO of course, I can change the sort order on the back end and the new order shows on the CPT archive but not on the tax archive. The problem is on the live site and on the development version of the site, which is on a different server. I can only think of two things: 1) this is an older site, it's been through some things :) Could there be something in the db? 2) Do either the custom taxonomy or the CPT require specific arguments? I'm using this plugin. I've tried a few different things but I'm stuck, I have no idea.

mplusb commented 2 years ago

another user having the same issue: https://wordpress.org/support/topic/doesnt-work-on-custom-post-type-categories/

codeflorist commented 1 year ago

the solution by JoshuaCrewe was not working for me. here is what worked for me:

add_filter('posts_orderby', function ($orderby, $query) {
    if (is_admin() || !$query->is_main_query() || !is_tax([ ... taxonomies ... ])) {
        return $orderby;
    }
    return 'wp_posts.menu_order ASC';
}, 10, 2);