michaeluno / admin-page-framework

Facilitates WordPress plugin and theme development.
http://admin-page-framework.michaeluno.jp/
Other
339 stars 71 forks source link

Q: Taxonomy Checklist filter output #166

Closed patrickf0 closed 9 years ago

patrickf0 commented 9 years ago

Hi Michael,

is there a way to e.g. exclude some term ids from the taxonomy checklist or only show parent items if taxonomy is hierarchical?

michaeluno commented 9 years ago

I've added the max_depth argument for the taxonomy field type in 3.3.2b. Download. You may try that.

Use it like this:

    array(  
        'field_id'              => 'taxonomy_checklist_all',
        'title'                 => __( 'Taxonomies', 'admin-page-framework-demo' ),
        'type'                  => 'taxonomy',
        'taxonomy_slugs'        => get_taxonomies( '', 'names' ),
        'max_depth'             => 1,   
    ),
michaeluno commented 9 years ago

Forget about the max_depth argument which just I deprecated to introduce the new query argument which gives you more freedom.

Use it like this.

    array(  
        'field_id'              => 'taxonomy_checklist_all',
        'title'                 => __( 'Custom Taxonomy Queries', 'admin-page-framework-demo' ),
        'type'                  => 'taxonomy',
        'taxonomy_slugs'        => get_taxonomies( '', 'names' ),
        'query'                 => array(
            'depth'     => 2,
            'orderby'   => 'term_id',
            'order'     => 'DESC',
            'exclude'   => '1', // removes the 'Uncategorized' category.
            // 'search' => 'PHP',
            // 'parent'    => 9,    // only show terms whose direct parent ID is 9.
            // 'child_of'  => 8,    // only show child terms of the term ID of 8.
        ),
    ),
patrickf0 commented 9 years ago

Thanks that´s what I need ;)

patrickf0 commented 9 years ago

Problem is: When I have two or more taxonomies, the query will effect all of them, instead of each one itself... you know?

michaeluno commented 9 years ago

Oh, I see. I'm not sure what would be a good syntax to support that.

Does introducing a new queries argument complicate the syntax? It will be like this:

    array(  
        'field_id'              => 'taxonomy_checklist_all',
        'title'                 => __( 'Custom Taxonomy Queries', 'admin-page-framework-demo' ),
        'type'                  => 'taxonomy',

        // (required) This defines the taxonomies to be listed.
        'taxonomy_slugs'        => get_taxonomies( '', 'names' ),

        // This defines the default query argument. For the structure and supported arguments, see http://codex.wordpress.org/Function_Reference/get_terms#Parameters
        'query'                 => array(
            'depth'     => 2,
            'orderby'   => 'term_id',
            'order'     => 'DESC',
            'exclude'   => '1', // removes the 'Uncategorized' category.
        ),

        // This allows to set query argument for each taxonomy.
        'queries'               => array(
            // taxonomy slug / id => query argument array
            'category'  =>  array(
                'depth'     => 2,
                'orderby'   => 'term_id',
                'order'     => 'DESC',
                'exclude'   => '1', // removes the 'Uncategorized' category.                        
            ),
            'tag'       => array(
                'orderby'   => 'name',
                'order'     => 'ASC',
                'exclude'   => '10,20,30', 
            )
        ),
    ),

I thought of nested arguments inside the query argument but the key names will conflict between the existing query argument keys and the taxonomy slugs.

patrickf0 commented 9 years ago

I think it´s okay this way... If you´re about to go in such detail, you should be aware that this is a bit deeper in syntax... those who do that, can handle such coding, I think ;)

michaeluno commented 9 years ago

Okay, updated. You may try that.