simple-custom-post-order icon indicating copy to clipboard operation
simple-custom-post-order copied to clipboard

Order not working on taxonomy archive

Open mplusb opened this issue 5 years ago • 5 comments

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

mplusb avatar Mar 03 '20 11:03 mplusb

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.

razvanaldea89 avatar Apr 21 '20 07:04 razvanaldea89

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 :)

JoshuaCrewe avatar Apr 30 '20 16:04 JoshuaCrewe

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.

Blindeman avatar Apr 01 '21 18:04 Blindeman

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

mplusb avatar Sep 23 '22 11:09 mplusb

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);

codeflorist avatar Oct 13 '23 12:10 codeflorist