WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 16 months ago

#42765 closed enhancement (invalid)

Add the filter to the taxonomy metabox when editing a post

Reported by: mihdan Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.9.1
Component: Taxonomy Keywords: needs-patch good-first-bug close
Focuses: administration Cc:
PR Number:

Description

The filter (default_term_id) is needed to set a default term in the custom taxonomy for custom post type.
File: /wp-admin/includes/meta-boxes.php, Line: 542

<div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
    <?php
    $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
    echo "<input type='hidden' name='{$name}[]' value=' . apply_filters( 'default_term_id', 0, tax_name ) . ' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
    ?>
    <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
        <?php wp_terms_checklist( $post->ID, array( 'taxonomy' => $tax_name, 'popular_cats' => $popular_ids ) ); ?>
    </ul>
</div>

Change History (8)

#1 @Responsor
2 years ago

Yes, make it happen please!

#2 @Sh14
2 years ago

It's really will be useful!

#3 @frontiercode
2 years ago

I think it's interesting feature. Get it!

#4 @campusboy1987
2 years ago

@mihdan proposal sounds very reasonable. After all, posts are not limited to categories.

#5 @SergeyBiryukov
16 months ago

  • Keywords needs-patch good-first-bug added
  • Milestone changed from Awaiting Review to Future Release

#6 @soulseekah
16 months ago

Michael, thank you for your ticket.

It seems that wp_terms_checklist_args is the filter you are looking for. It can be used to override the selected_cats argument. If it's empty set the default as needed.

#7 @mihdan
16 months ago

  • Keywords close added

@soulseekah, thanks for the clarification. Solved my problem with the filter wp_terms_checklist_args.

@SergeyBiryukov, the ticket can be closed.

#8 @soulseekah
16 months ago

  • Milestone Future Release deleted
  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.