$taxonomy_terms) { $tax_query[]=array( 'taxonomy' => $taxonomy, 'terms' => $taxonomy_terms, 'field' => 'slug', ); } $query['tax_query']=$tax_query; $posts=get_posts($query); $options=array(); foreach($posts as $post) $options[$post->post_name]=$post->post_title; return $options; } elseif($field['static-options']) { $options=array(); foreach($field['static-options'] as $static_option) $options[$static_option['value']]=$static_option['label']; return $options; } else return $field['options']; } /** @brief If @b $value is set, returns @b $value; otherwise, returns the default value. @param array $field Array of field settings. @param mixed $value The value from the database. @since 1.0.0 @see $cff_custom_field */ function cff_get_field_value($field, $value) { if(isset($value)) return $value; elseif(isset($field['value'])) return $field['value']; else return null; } /** @brief Shows the field value. @param array $field Array of field settings. @param mixed $value The value from the database. @since 1.0.0 @see $cff_custom_field */ function cff_field_value($field, $value) { $value=cff_get_field_value($field, $value); if(isset($value)) echo 'value="', esc_attr($value), '" '; } /** @brief Shows the field attributes. @param array $field Array of field settings. @since 1.0.0 @see $cff_custom_field */ function cff_field_attributes($field) { $attributes=array( 'readonly', 'required', 'disabled', 'autofocus', 'multiple', ); foreach($attributes as $attribute) if($field[$attribute]) echo $attribute, ' '; $attributes=array( 'placeholder', 'pattern', 'min', 'max', 'step', ); foreach($attributes as $attribute) if($field[$attribute] || $field[$attribute]===0) echo $attribute, '="', esc_attr($field[$attribute]), '" '; if($field['autocomplete']) echo 'autocomplete=', $field['autocomplete']? '"on" ': '"off" '; } /** @brief Shows the field scripts. @param array $field Array of field settings. @since 1.0.0 @see $cff_custom_field */ function cff_field_scripts($field) { $scripts=array( 'onblur', 'onchange', 'oncontextmenu', 'onfocus', 'oninput', 'oninvalid', 'onreset', 'onsearch', 'onselect', 'onsubmit', ); foreach($scripts as $script) { if($field[$script]) echo esc_js($script), '="', esc_js($field[$script]), '" '; } } /** @brief Shows the field classes. @param array $field Array of field settings. @since 1.0.0 @see $cff_custom_field */ function cff_field_class($field) { echo 'class="cff-', esc_attr($field['type']), '-field" '; } ?>