• Как добавить кнопку выбрать все рубрики/категории в админку?

    @Steamvis Автор вопроса
    Сделал для себя такое решение
    <div style="display: block; padding:20px 0px;">
    	        <label for="checkAll_taxonomies" >
    	            <button id="checkAll_taxonomies" type="button" class="button button-primary" onclick="setTrueAllCheckBoxes()">Выбрать все</button>
    	        </label>
    			<label for="checkAll_taxonomies">
    	            <button id="checkAll_taxonomies" type="button" class="button button-primary" onclick="setFalseAllCheckBoxes()">Снять все</button>
    	        </label>
     </div>

    function setTrueAllCheckBoxes() {
                    let checkboxes = document.getElementsByName("tax_input[<?= $tax_name ?>][]");
                    for (let index = 0; index < checkboxes.length; index++) {
                        if(checkboxes[index].checked === false) {
                            checkboxes[index].checked = true;
                        }
                    }
                }
                function setFalseAllCheckBoxes() {
                    let checkboxes = document.getElementsByName("tax_input[<?= $tax_name ?>][]");
                    for (let index = 0; index < checkboxes.length; index++) {
                        if(checkboxes[index].checked === true) {
                            checkboxes[index].checked = false;
                        }
                    }
                }

    шаблон скопировал из post_categories_meta_box и создал свою функцию в functions и вставил туда код сверху
    function get_all_categories_box( $post, $box ) {
    	$defaults = array( 'taxonomy' => 'category' );
    	if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) {
    		$args = array();
    	} else {
    		$args = $box['args'];
    	}
    	$parsed_args = wp_parse_args( $args, $defaults );
    	$tax_name    = esc_attr( $parsed_args['taxonomy'] );
    	$taxonomy    = get_taxonomy( $parsed_args['taxonomy'] );
    
    	// Вкладки категории/часто используемые - tabs
    	?>
        <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
            <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
                <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a>
                </li>
                <li class="hide-if-no-js"><a
                            href="#<?php echo $tax_name; ?>-pop"><?php echo esc_html( $taxonomy->labels->most_used ); ?></a>
                </li>
            </ul>
    
            <?php
            // вкладка часто используемые
            ?>
            <div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;">
                <ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear">
    				<?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?>
                </ul>
            </div>
    
            <?php
            // вкладка категорий
            ?>
    
    	    <div style="display: block; padding:20px 0px;">
    	        <label for="checkAll_taxonomies" >
    	            <button id="checkAll_taxonomies" type="button" class="button button-primary" onclick="setTrueAllCheckBoxes()">Выбрать все</button>
    	        </label>
    			<label for="checkAll_taxonomies">
    	            <button id="checkAll_taxonomies" type="button" class="button button-primary" onclick="setFalseAllCheckBoxes()">Снять все</button>
    	        </label>
            </div>
            <script>
                function setTrueAllCheckBoxes() {
                    let checkboxes = document.getElementsByName("tax_input[<?= $tax_name ?>][]");
                    for (let index = 0; index < checkboxes.length; index++) {
                        if(checkboxes[index].checked === false) {
                            checkboxes[index].checked = true;
                        }
                    }
                }
                function setFalseAllCheckBoxes() {
                    let checkboxes = document.getElementsByName("tax_input[<?= $tax_name ?>][]");
                    for (let index = 0; index < checkboxes.length; index++) {
                        if(checkboxes[index].checked === true) {
                            checkboxes[index].checked = false;
                        }
                    }
                }
            </script>
    
            <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='0' />"; // 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>
    		<?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?>
                <div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children">
                    <a id="<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add"
                       class="hide-if-no-js taxonomy-add-new">
    					<?php
    					/* translators: %s: Add New taxonomy label. */
    					printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
    					?>
                    </a>
                    <p id="<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
                        <label class="screen-reader-text"
                               for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label>
                        <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>"
                               class="form-required form-input-tip"
                               value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" aria-required="true"/>
                        <label class="screen-reader-text" for="new<?php echo $tax_name; ?>_parent">
    						<?php echo $taxonomy->labels->parent_item_colon; ?>
                        </label>
    					<?php
    					$parent_dropdown_args = array(
    						'taxonomy'         => $tax_name,
    						'hide_empty'       => 0,
    						'name'             => 'new' . $tax_name . '_parent',
    						'orderby'          => 'name',
    						'hierarchical'     => 1,
    						'show_option_none' => '&mdash; ' . $taxonomy->labels->parent_item . ' &mdash;',
    					);
    					$parent_dropdown_args = apply_filters( 'post_edit_category_parent_dropdown_args', $parent_dropdown_args );
    
    					wp_dropdown_categories( $parent_dropdown_args );
    					?>
                        <input type="button" id="<?php echo $tax_name; ?>-add-submit"
                               data-wp-lists="add:<?php echo $tax_name; ?>checklist:<?php echo $tax_name; ?>-add"
                               class="button category-add-submit"
                               value="<?php echo esc_attr( $taxonomy->labels->add_new_item ); ?>"/>
    					<?php wp_nonce_field( 'add-' . $tax_name, '_ajax_nonce-add-' . $tax_name, false ); ?>
                        <span id="<?php echo $tax_name; ?>-ajax-response"></span>
                    </p>
                </div>
    		<?php endif; ?>
        </div>
    	<?php
    }


    и добавил имя функции в register_taxonomy в поле meta_box_cb

    register_taxonomy(
            'hireo_brands',
            array(
                'hireo_service',
                'hireo_shop',
                'hireo_technique',
            ),
            array(
                'labels'       => array(
                    'name'          => 'Бренды',
                    'singular_name' => 'Бренд',
                ),
                'meta_box_cb'  => 'get_all_categories_box',
            )
        );
    Ответ написан
    Комментировать