UPDATE
The custom SQL query below can be used to produce a list of unique types taxonomy terms that have been assigned to newsroom posts. In PHP, you can call the function get_newsroom_types_terms to get the list: $terms = get_newsroom_types_terms();
.
Custom SQL query
function get_newsroom_types_terms() {
global $wpdb;
$table_prefix = $wpdb->prefix;
$taxonomy = 'types';
$post_type="newsroom";
$sql = <<<EOSQL
SELECT DISTINCT T.term_id, T.name, T.slug
FROM {$table_prefix}terms T
JOIN {$table_prefix}term_taxonomy TT ON ( TT.term_id = T.term_id )
JOIN {$table_prefix}term_relationships TR ON ( TR.term_taxonomy_id = TT.term_taxonomy_id )
JOIN {$table_prefix}posts P ON ( P.ID = TR.object_id )
WHERE TT.taxonomy = %s
AND P.post_type = %s
ORDER BY T.name
EOSQL;
$query = $wpdb->prepare( $sql, $taxonomy, $post_type );
$terms = $wpdb->get_results( $query, \OBJECT );
return $terms;
}
HTML Form
Please see my comment.
The PHP/HTML code for the form has several problems.
- It partially hardcodes the URL for admin-ajax.php.
- admin-ajax.php is not requested from an AJAX call.
- There is no indication of the default state for checkboxes.
- There is no code indicating how checkbox states are updated.
- Material-UI class names are hardcoded even though Material-UI uses ReactJS to render its HTML.
Please read the WordPress Documentation on How Do I Use AJAX?