Reorder multiple CPTs with the same category
-
Hi
First of all, your plugin is great but I stumbled upon some issues. ( Or I’m missing some info )
The hooks ‘reOrder_query_join’, ‘reOrder_query_where’, ‘reOrder_query_orderby’, don’t check by post_type. This alters the SQL for queries where post_types share the same category.
To solve this, I’ve added some code and a function:
Inside each of the hooks ‘reOrder_query_join’, ‘reOrder_query_where’, ‘reOrder_query_orderby’; I’ve added an if statement to break the hook.if( false == $this->check_if_cpt_is_sortable( $wp_query->get( "post_type" ) ) ) return $args;
This fail safe uses a function ‘check_if_cpt_is_sortable’, which searches the AdminOptions. The function looks like this:
public function check_if_cpt_is_sortable( $post_type = '' ) { //= bail early if( empty( $post_type ) ) return false; //= get admin options $options = $this->getAdminOptions(); //= bail; admin options empty if( !isset( $options[ 'categories_checked' ] ) ) return false; //= loop foreach( $options[ 'categories_checked' ] as $key => $value ) { if( $key == $post_type ) return true; } //= no results return return false; }
Note: This does only solve enabling / disabling post_types sharing the same category.
I also stumbled upon another issue, which I didn’t resolve: When enabling multiple post_types sharing the same category. The reorder page show’s all posts shared between that category you want to sort. In my case, this isn’t the desired behaviour. I want to sort the posts per category AND per cpt.
Anyway, I hope all this information helps some of you.
- The topic ‘Reorder multiple CPTs with the same category’ is closed to new replies.