我对自定义帖子类型有美国州的自定义分类。目前,当向这个自定义帖子类型添加新帖子时,我必须手动检查所有50个状态(如果适用)是否有一种方法可以在自定义分类法元框内添加一个按钮,当按下它时会检查所有框以指定帖子到所有50个州?
答案 0 :(得分:1)
所以这就是我添加它的方式: 我将此代码添加到functions.php:
中//Add Script to CPT Page
add_action( 'admin_print_scripts-post-new.php', 'portfolio_admin_script', 11 );
add_action( 'admin_print_scripts-post.php', 'portfolio_admin_script', 11 );
function portfolio_admin_script() {
global $post_type;
if( 'counselor' == $post_type )
wp_enqueue_script( 'portfolio-admin-script', get_stylesheet_directory_uri() . '/js/counselor.js' );
}
function style_state_button() {
echo '<style type="text/css">
#select-all-states-btn {
margin-top: 15px;
}
#statesserved-adder h4 {
display: none;
}
</style>';
}
add_action('admin_head', 'style_state_button');
这会调用一个名为counselor.js的javascript文件。在那个档案中是这样的:
jQuery(document).ready(function() {
jQuery('div#statesserved-adder ').prepend('<input type="button" class="button" id="select-all-states-btn" value="Select All States" />');
jQuery("#select-all-states-btn").click(function() {
var checkBoxes = jQuery('input[name="tax_input[statesserved][]"]');
checkBoxes.attr("checked", !checkBoxes.attr("checked"));
});
});