Skip to content

Instantly share code, notes, and snippets.

@barryhughes
Created July 17, 2017 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barryhughes/a1e3a7df163f6386ea8fc74c233ca60f to your computer and use it in GitHub Desktop.
Save barryhughes/a1e3a7df163f6386ea8fc74c233ca60f to your computer and use it in GitHub Desktop.
<?php
// Don't load directly
defined( 'WPINC' ) or die;
$selected_terms = array();
$taxonomy_obj = get_taxonomy( $taxonomy );
$ajax_args = array(
'taxonomy' => $taxonomy,
);
$taxonomy_label = $taxonomy_obj->label;
// If we already have Event on the actual Taxonomy Label
if ( false === strpos( $taxonomy_obj->label, tribe_get_event_label_singular() ) ) {
$taxonomy_label = sprintf( '%s %s', tribe_get_event_label_singular(), $taxonomy_obj->label );
}
// Check we have terms
$has_terms = count( get_terms( $taxonomy, array( 'hide_empty' => false, 'number' => 1, 'fields' => 'ids' ) ) ) < 1;
// Setup selected tags
$value = ! empty( $_POST['tax_input'][ $taxonomy ] ) ? explode( ',', esc_attr( trim( $_POST['tax_input'][ $taxonomy ] ) ) ) : array();
// if no tags from $_POST then look for saved tags
if ( empty( $value ) ) {
$terms = wp_get_post_terms( get_the_ID(), $taxonomy );
$value = wp_list_pluck( $terms, 'term_id' );
}
foreach ( $value as $term_id ) {
$term = get_term( $term_id, $taxonomy );
$selected_terms[ $term_id ] = array(
'id' => $term->term_id,
'text' => $term->name,
);
}
if ( is_array( $value ) ) {
$value = implode( ',', $value );
}
if ( $has_terms ) {
return;
}
?>
<div class="tribe-section tribe-section-taxonomy">
<div class="tribe-section-header">
<h3><?php echo esc_html( $taxonomy_label ); ?></h3>
</div>
<?php
/**
* Allow developers to hook and add content to the beginning of this section
* @param string $taxonomy_slug
*/
do_action( 'tribe_events_community_section_before_taxonomy', $taxonomy );
?>
<?php foreach ( get_terms( array( 'taxonomy' => $taxonomy, 'get' => 'all' ) ) as $term ): ?>
<label>
<input
type="checkbox"
name="tax_input[<?php echo esc_attr( $taxonomy ); ?>][]"
value="<?php echo esc_attr( $term->term_id ); ?>"
<?php echo isset( $selected_terms[ $term->term_id ] ) ? 'checked="checked"' : ''; ?>
/>
<?php echo esc_html( $term->name ); ?>
</label> <br/>
<?php endforeach; ?>
<?php
/**
* Allow developers to hook and add content to the end of this section
* @param string $taxonomy_slug
*/
do_action( 'tribe_events_community_section_after_taxonomy', $taxonomy );
?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment