Пример #1
0
 /**
  * The constructor.
  *
  * @param int $id
  */
 public function __construct($id = 0)
 {
     $this->id = papi_get_term_id($id);
     $this->term = get_term($this->id, '');
     $id = papi_get_taxonomy_type_id($this->id);
     $this->type_class = papi_get_entry_type_by_id($id);
 }
Пример #2
0
/**
 * Get WordPress taxonomy in various ways.
 *
 * @param  int $term_id
 *
 * @return string
 */
function papi_get_taxonomy($term_id = null)
{
    if ($taxonomy = papi_get_or_post('taxonomy')) {
        return $taxonomy;
    }
    $term_id = papi_get_term_id($term_id);
    if ($term_id !== 0) {
        $term = get_term($term_id, '');
        if (is_object($term) && !is_wp_error($term)) {
            return strtolower($term->taxonomy);
        }
    }
    return '';
}
Пример #3
0
/**
 * Set taxonomy type to a term.
 *
 * @param  mixed  $term_id
 * @param  string $taxonomy_type
 *
 * @return bool
 */
function papi_set_taxonomy_type_id($term_id, $taxonomy_type)
{
    if (papi_entry_type_exists($taxonomy_type)) {
        return update_term_meta(papi_get_term_id($term_id), papi_get_page_type_key(), $taxonomy_type);
    }
    return false;
}
Пример #4
0
/**
 * Update property with new value. The old value will be deleted.
 *
 * @param  int    $term_id
 * @param  string $slug
 * @param  mixed  $value
 *
 * @return bool
 */
function papi_update_term_field($term_id = null, $slug = null, $value = null)
{
    if (!is_numeric($term_id) && is_string($term_id)) {
        $value = $slug;
        $slug = $term_id;
        $term_id = null;
    }
    if (!is_string($slug) || empty($slug)) {
        return false;
    }
    if (papi_is_empty($value)) {
        return papi_delete_term_field($term_id, $slug);
    }
    return papi_update_field(papi_get_term_id($term_id), $slug, $value, 'term');
}