<?php 
function get_terms_dropdown($taxonomies, $args)
{
    $myterms = get_terms($taxonomies, $args);
    $optionname = "event-type";
    $emptyvalue = "0";
    $output = "<div class='select-wrapper'><select name='" . $optionname . "'><option selected='" . $selected . "' value='" . $emptyvalue . "'>Select event type</option>'";
    foreach ($myterms as $term) {
        $term_taxonomy = $term->event - type;
        $term_slug = $term->slug;
        $term_name = $term->name;
        $link = $term_slug;
        if (is_tax('event-type', $term_slug)) {
            $selected = "selected";
        } else {
            $selected = "";
        }
        $output .= "<option name='" . $link . "' value='" . $link . "' " . $selected . ">" . $term_name . "</option>";
    }
    $output .= "</select></div>";
    return $output;
}
$taxonomies = array('event-type');
$args = array('order' => 'ASC', 'hide_empty' => true);
echo get_terms_dropdown($taxonomies, $args);
?>
      </div>
    </form>
  </div>
</div>
Ejemplo n.º 2
0
 public function render_metabox($post)
 {
     // Add nonce for security and authentication.
     wp_nonce_field('day1fx_nonce_action', 'day1fx_nonce');
     // Retrieve an existing value from the database.
     $day1fx_day1date_ = get_post_meta($post->ID, 'day1fx_day1date_', true);
     $day1fx_day1fxhigh_ = get_post_meta($post->ID, 'day1fx_day1fxhigh_', true);
     $day1fx_day1fxlow_ = get_post_meta($post->ID, 'day1fx_day1fxlow_', true);
     $day1fx_day1wxdesc_ = get_post_meta($post->ID, 'day1fx_day1wxdesc_', true);
     $day1fx_day1disc_ = get_post_meta($post->ID, 'day1fx_day1disc_', true);
     // Set default values.
     if (empty($day1fx_day1date_)) {
         $day1fx_day1date_ = '';
     }
     if (empty($day1fx_day1fxhigh_)) {
         $day1fx_day1fxhigh_ = '';
     }
     if (empty($day1fx_day1fxlow_)) {
         $day1fx_day1fxlow_ = '';
     }
     if (empty($day1fx_day1wxdesc_)) {
         $day1fx_day1wxdesc_ = '';
     }
     if (empty($day1fx_day1disc_)) {
         $day1fx_day1disc_ = '';
     }
     // Form fields.
     echo '<table class="form-table">';
     echo '	<tr>';
     echo '		<th><label for="day1fx_day1date_" class="day1fx_day1date__label">' . __('Date', 'text_domain') . '</label></th>';
     echo '		<td>';
     echo '			<input type="date" id="day1fx_day1date_" name="day1fx_day1date_" class="day1fx_day1date__field" placeholder="' . esc_attr__('', 'text_domain') . '" value="' . esc_attr__($day1fx_day1date_) . '">';
     echo '			<p class="description">' . __('Date of the day 1 forecast.', 'text_domain') . '</p>';
     echo '		</td>';
     echo '	</tr>';
     echo '	<tr>';
     echo '		<th><label for="day1fx_day1fxhigh_" class="day1fx_day1fxhigh__label">' . __('High Temperature', 'text_domain') . '</label></th>';
     echo '		<td>';
     echo '			<input type="number" id="day1fx_day1fxhigh_" name="day1fx_day1fxhigh_" class="day1fx_day1fxhigh__field" placeholder="' . esc_attr__('72', 'text_domain') . '" value="' . esc_attr__($day1fx_day1fxhigh_) . '">';
     echo '			<p class="description">' . __('High temperature for day 1.', 'text_domain') . '</p>';
     echo '		</td>';
     echo '	</tr>';
     echo '	<tr>';
     echo '		<th><label for="day1fx_day1fxlow_" class="day1fx_day1fxlow__label">' . __('Low Temperature', 'text_domain') . '</label></th>';
     echo '		<td>';
     echo '			<input type="number" id="day1fx_day1fxlow_" name="day1fx_day1fxlow_" class="day1fx_day1fxlow__field" placeholder="' . esc_attr__('', 'text_domain') . '" value="' . esc_attr__($day1fx_day1fxlow_) . '">';
     echo '			<p class="description">' . __('Low temperature for day 1.', 'text_domain') . '</p>';
     echo '		</td>';
     echo '	</tr>';
     echo '	<tr>';
     echo '		<th><label for="day1fx_day1wxdesc_" class="day1fx_day1wxdesc__label">' . __('Weather Description', 'text_domain') . '</label></th>';
     echo '		<td>';
     get_terms_dropdown($taxonomies, $args);
     echo '			<p class="description">' . __('Description of the weather for day 1.', 'text_domain') . '</p>';
     echo '		</td>';
     echo '	</tr>';
     echo '	<tr>';
     echo '		<th><label for="day1fx_day1disc_" class="day1fx_day1disc__label">' . __('Discussion', 'text_domain') . '</label></th>';
     echo '		<td>';
     wp_editor($day1fx_day1disc_, 'day1fx_day1disc_', array('media_buttons' => true));
     echo '			<p class="description">' . __('Discussion about the forecast for day 1.', 'text_domain') . '</p>';
     echo '		</td>';
     echo '	</tr>';
     echo '</table>';
 }