This code will be useful when you have to manually create a form where users need to select from existing
categories or custom taxonomies.
If you want to test it out create a php file in wp-content/mu-plugins/terms.php
Note: If mu-plugins folder doesn't exist just create it.
WordPress runs and activates plugins from that folder automatically.
The categories should be displayed within your site's footer.
Another possible use is to create a shortcode that way the checkboxes will appear within the page's content.
[code]
add_action('wp_footer', 'orb_terms_example');
function orb_terms_example() {
$tax = 'category'; // or custom one
$post_id = 0;
$select_tax_ids = array(1, 2, 3);
$checkbox_args = array(
'selected_cats' => $select_tax_ids,
'taxonomy' => $tax,
);
if ( ! is_admin() && ! function_exists('wp_terms_checklist') ) {
include_once ABSPATH . 'wp-admin/includes/template.php';
}
echo wp_terms_checklist($post_id, $checkbox_args);
}
[/code]