• thewebtailors

    (@thewebtailors)


    Even though “Show / Hide re-order interface” and “Archive Drag&Drop” is only enabled on one custom post type (Board Members), it also affects the order of other custom post types (e.g. Grant Recipients). “Admin Sort” is turned on. When I try changing the default order of Grant Recipients in the backend with the code below, it just gets ignored:

    add_action( 'pre_get_posts', array( $this, 'backend_default_order' ),999);
    
    function backend_default_order($query) {
    		if( is_admin() && 'grant_recipient' === ($_GET['post_type'] ?? '') && !isset($_GET['orderby']) ) {
    			$query->set( 'orderby',  'title' );
    			$query->set( 'order',  'ASC' );
            }
        }

    Only if I use the following code, I can change the default order:

    add_filter( 'pto/posts_orderby/ignore', array( $this, 'ignore_post_types_order_sort' ), 10, 3 );
    
    	function ignore_post_types_order_sort( $ignore, $orderBy, $query ) {
    		if ( isset( $query->query_vars ) && ! empty( $query->query_vars['post_type'] ) ) {
    			$query_post_types = array();
    			foreach ( (array) $query->query_vars['post_type'] as $_post_type ) {
    				$query_post_types[] = $_post_type;
    			}
    
    			if ( in_array( "grant_recipient", $query_post_types ) ) {
    				$ignore = true;
    			}
    		}
    
    		return $ignore;
    	}

    Would it be possible for your plugin to not affect the admin order for post types which are not enabled through your plugin?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Affects order of other post types’ is closed to new replies.