0

How to add some extra filter to Category Taxonomy list to backend, just after Bulk Action Drop-down want to add another filter Drop-down. For example, search only parent category or search with some custom meta added to category etc.

enter image description here

0

Exclude child categories when getting posts from parent:

use category__in

Here using category id:

$query = new WP_Query( array( 'category__in' => 4 ) );

Excluding children of custom taxonomies:

tax_query argument of WP_Query has include_children set to true by default, so you can set that to false.

include_children (boolean) - Whether or not to include children for hierarchical taxonomies. Defaults to true.

    $args = array(
    'post_type' => 'post',
    'tax_query' => array(
        array(
            'taxonomy' => 'people',
            'include_children' => false,
        ),
    ),
);
$query = new WP_Query( $args );

Excluding Children and only getting posts in category 4 with people taxonomy:

    $args = array(
    'post_type' => 'post',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'category',
            'field'    => 'term_id',
            'terms'    => 4,
            'include_children' => false,
        ),
        array(
            'taxonomy' => 'people',
        ),
    ),
);
$query = new WP_Query( $args );

NOTE: see the Tax_query link above for more nested/complicated queries.

| improve this answer | |
  • Hi @hwl thanks for the reply. But I am looking for backend Category list filter. I have edited my question, hope you can get it. – Joydeep Mondal May 16 '17 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.