当前位置: 首页>>代码示例>>PHP>>正文


PHP get_object_term_cache函数代码示例

本文整理汇总了PHP中get_object_term_cache函数的典型用法代码示例。如果您正苦于以下问题:PHP get_object_term_cache函数的具体用法?PHP get_object_term_cache怎么用?PHP get_object_term_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_object_term_cache函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_tags_from_current_posts

 /**
  * Get tags from current post views
  *
  * @return boolean
  */
 public static function get_tags_from_current_posts()
 {
     if (is_array(self::$posts) && count(self::$posts) > 0) {
         // Generate SQL from post id
         $postlist = implode("', '", self::$posts);
         // Generate key cache
         $key = md5(maybe_serialize($postlist));
         $results = array();
         // Get cache if exist
         $cache = wp_cache_get('generate_keywords', 'simpletags');
         if ($cache === false) {
             foreach (self::$posts as $object_id) {
                 // Get terms
                 $terms = get_object_term_cache($object_id, 'post_tag');
                 if (false === $terms) {
                     $terms = wp_get_object_terms($object_id, 'post_tag');
                 }
                 if ($terms != false) {
                     $results = array_merge($results, $terms);
                 }
             }
             $cache[$key] = $results;
             wp_cache_set('generate_keywords', $cache, 'simpletags');
         } else {
             if (isset($cache[$key])) {
                 return $cache[$key];
             }
         }
         return $results;
     }
     return array();
 }
开发者ID:EasterAndJay,项目名称:tamichelew.com,代码行数:37,代码来源:class.client.autolinks.php

示例2: add_attachment_fields_to_edit

 static function add_attachment_fields_to_edit($form_fields, $post)
 {
     $terms = get_object_term_cache($post->ID, self::TAXONOMY);
     $field = array();
     $taxonomy_obj = (array) get_taxonomy(self::TAXONOMY);
     if (!$taxonomy_obj['public'] || !$taxonomy_obj['show_ui']) {
         continue;
     }
     if (false === $terms) {
         $terms = wp_get_object_terms($post->ID, self::TAXONOMY);
     }
     $values = wp_list_pluck($terms, 'term_id');
     ob_start();
     wp_terms_checklist($post->ID, array('taxonomy' => self::TAXONOMY, 'checked_ontop' => false, 'walker' => new Walker_WP_Media_Taxonomy_Checklist($post->ID)));
     $output = ob_get_clean();
     if (!empty($output)) {
         $output = '<ul class="term-list">' . $output . '</ul>';
         $output .= wp_nonce_field('save_attachment_media_categories', 'media_category_nonce', false, false);
     } else {
         $output = '<ul class="term-list"><li>No ' . $taxonomy_obj['label'] . '</li></ul>';
     }
     $field = array('label' => !empty($taxonomy_obj['label']) ? $taxonomy_obj['label'] : self::TAXONOMY, 'value' => join(', ', $values), 'show_in_edit' => false, 'input' => 'html', 'html' => $output);
     $form_fields[self::TAXONOMY] = $field;
     return $form_fields;
 }
开发者ID:kevinlangleyjr,项目名称:wp-media-categories,代码行数:25,代码来源:wp-media-categories.php

示例3: get_object_term

 /**
  * Wrap wp_get_object_terms to cache it and return only one object
  * inspired by the function get_the_terms
  *
  * @since 1.2
  *
  * @param int    $object_id post_id or term_id
  * @param string $taxonomy  Polylang taxonomy depending if we are looking for a post ( or term ) language ( or translation )
  * @return bool|object the term associated to the object in the requested taxonomy if exists, false otherwise
  */
 public function get_object_term($object_id, $taxonomy)
 {
     if (empty($object_id)) {
         return false;
     }
     $object_id = (int) $object_id;
     $term = get_object_term_cache($object_id, $taxonomy);
     if (false === $term) {
         // query language and translations at the same time
         $taxonomies = array($this->tax_language, $this->tax_translations);
         // query terms
         foreach (wp_get_object_terms($object_id, $taxonomies) as $t) {
             $terms[$t->taxonomy] = $t;
             if ($t->taxonomy == $taxonomy) {
                 $term = $t;
             }
         }
         // store it the way WP wants it
         // set an empty cache if no term found in the taxonomy
         foreach ($taxonomies as $tax) {
             wp_cache_add($object_id, empty($terms[$tax]) ? array() : array($terms[$tax]), $tax . '_relationships');
         }
     } else {
         $term = reset($term);
     }
     return empty($term) ? false : $term;
 }
开发者ID:spielhoelle,项目名称:amnesty,代码行数:37,代码来源:translated-object.php

示例4: get_tags

 function get_tags($postid)
 {
     $tags = get_object_term_cache($postid, 'post_tag');
     if (false === $tags) {
         $tags = wp_get_object_terms($postid, 'post_tag');
     }
     $tags = apply_filters('get_the_tags', $tags);
     if (!empty($tags)) {
         foreach ($tags as $tag) {
             $newtags[] = $tag->name;
         }
         $tags = implode(',', $newtags);
     } else {
         $tags = '';
     }
     return $tags;
 }
开发者ID:blueblazeassociates,项目名称:headspace2,代码行数:17,代码来源:headspace_library.php

示例5: attach_actions_meta

/**
 *  Attach information about a question's topic 
 */
function attach_actions_meta(&$post)
{
    if ($post->post_type === 'question') {
        // Try to get tax
        // Term cache should already be primed by 'update_post_term_cache'.
        $terms = get_object_term_cache($post->ID, 'faq-topic');
        // Guess not
        if (empty($terms)) {
            $terms = wp_get_object_terms($post->ID, 'faq-topic');
            wp_cache_add($post->ID, $terms, 'faq-topic' . '_relationships');
        }
        // We got some hits
        if (!empty($terms)) {
            $interim_term = false;
            foreach ($terms as $key => $term) {
                if (!$interim_term || $term->parent) {
                    $interim_term = $term;
                }
            }
            $post->term = $interim_term->slug;
        }
        $post->action_attr = 'answers';
        $post->action_hash = '/' . $post->term . '/' . $post->post_name;
    } elseif ($post->post_type === 'payment') {
        $post->action_attr = 'payments';
        $post->action_hash = '/' . $post->post_name;
    } elseif ($post->post_type === 'issue') {
        $issue_type = get_post_meta($post->ID, 'issue_category_type', true);
        switch ($issue_type) {
            case 'link':
                $post->action_url = get_post_meta($post->ID, 'url', true);
                return;
            case 'iframe':
                $post->action_attr = 'report';
                $post->action_hash = '/embed/' . $post->post_name;
                break;
            case 'form':
                $post->action_url = $post->guid;
                break;
        }
    }
    return;
}
开发者ID:proudcity,项目名称:wp-proud-actions-app,代码行数:46,代码来源:wp-proud-actions-app.php

示例6: get_the_series

/**
 * get_the_series() - calls up all the series info from the taxonomy tables (for a particular post).
*/
function get_the_series($id = false, $cache = true)
{
    global $post, $term_cache;
    $id = (int) $id;
    if (!$id && (!empty($post) || $post != '' || $post != null)) {
        $id = (int) $post->ID;
    }
    if (empty($id)) {
        return false;
    }
    $series = $cache ? get_object_term_cache($id, 'series') : false;
    if (false === $series) {
        $series = wp_get_object_terms($id, 'series');
    }
    $series = apply_filters('get_the_series', $series);
    //adds a new filter for users to hook into
    if (!empty($series)) {
        usort($series, '_usort_terms_by_name');
    }
    return $series;
}
开发者ID:briancfeeney,项目名称:portigal,代码行数:24,代码来源:orgSeries-taxonomy.php

示例7: get_blogtrip_taxonomies

function get_blogtrip_taxonomies($post = 0, $args = array(), $format = '')
{
    if (is_int($post)) {
        $post =& get_post($post);
    } elseif (!is_object($post)) {
        $post =& $GLOBALS['post'];
    }
    $args = wp_parse_args($args, array('template' => '%s: %l.'));
    extract($args, EXTR_SKIP);
    $taxonomies = array();
    if (!$post) {
        return $taxonomies;
    }
    foreach (get_object_taxonomies($post) as $taxonomy) {
        $t = (array) get_taxonomy($taxonomy);
        if (empty($t['label'])) {
            $t['label'] = $taxonomy;
        }
        if (empty($t['args'])) {
            $t['args'] = array();
        }
        if (empty($t['template'])) {
            $t['template'] = $template;
        }
        $terms = get_object_term_cache($post->ID, $taxonomy);
        if (empty($terms)) {
            $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
        }
        if ('' != $format) {
            $taxonomies[$taxonomy] = array();
            foreach ($terms as $term) {
                $taxonomies[$taxonomy][$term->slug] = isset($term->{$format}) ? $term->{$format} : $term->name;
            }
        } else {
            $taxonomies[$taxonomy] = $terms;
        }
    }
    return $taxonomies;
}
开发者ID:digideskio,项目名称:Travelllll,代码行数:39,代码来源:departure-display.php

示例8: get_the_tags

 function get_the_tags($id = 0)
 {
     $tags = $this->tags;
     if (is_single() || is_page()) {
         global $post;
         $id = (int) $id;
         if (!$id) {
             $id = (int) $post->ID;
         }
         $tagsextra = get_object_term_cache($id, 'post_tag');
         if (false === $tagsextra) {
             $tagsextra = wp_get_object_terms($id, 'post_tag');
         }
         $tagsextra = apply_filters('get_the_tags', $tagsextra);
         if (!empty($tagsextra)) {
             foreach ($tagsextra as $tag) {
                 $newtags[] = $tag->name;
             }
             $tags .= ',' . implode(',', $newtags);
         }
     }
     return trim($tags, ',');
 }
开发者ID:blueblazeassociates,项目名称:headspace2,代码行数:23,代码来源:tags.php

示例9: get_inline_data

/**
 * Adds hidden fields with the data for use in the inline editor for posts and pages.
 *
 * @since 2.7.0
 *
 * @param WP_Post $post Post object.
 */
function get_inline_data($post)
{
    $post_type_object = get_post_type_object($post->post_type);
    if (!current_user_can('edit_post', $post->ID)) {
        return;
    }
    $title = esc_textarea(trim($post->post_title));
    /** This filter is documented in wp-admin/edit-tag-form.php */
    echo '
<div class="hidden" id="inline_' . $post->ID . '">
	<div class="post_title">' . $title . '</div>' . '<div class="post_name">' . apply_filters('editable_slug', $post->post_name, $post) . '</div>
	<div class="post_author">' . $post->post_author . '</div>
	<div class="comment_status">' . esc_html($post->comment_status) . '</div>
	<div class="ping_status">' . esc_html($post->ping_status) . '</div>
	<div class="_status">' . esc_html($post->post_status) . '</div>
	<div class="jj">' . mysql2date('d', $post->post_date, false) . '</div>
	<div class="mm">' . mysql2date('m', $post->post_date, false) . '</div>
	<div class="aa">' . mysql2date('Y', $post->post_date, false) . '</div>
	<div class="hh">' . mysql2date('H', $post->post_date, false) . '</div>
	<div class="mn">' . mysql2date('i', $post->post_date, false) . '</div>
	<div class="ss">' . mysql2date('s', $post->post_date, false) . '</div>
	<div class="post_password">' . esc_html($post->post_password) . '</div>';
    if ($post_type_object->hierarchical) {
        echo '<div class="post_parent">' . $post->post_parent . '</div>';
    }
    if ($post->post_type == 'page') {
        echo '<div class="page_template">' . esc_html(get_post_meta($post->ID, '_wp_page_template', true)) . '</div>';
    }
    if (post_type_supports($post->post_type, 'page-attributes')) {
        echo '<div class="menu_order">' . $post->menu_order . '</div>';
    }
    $taxonomy_names = get_object_taxonomies($post->post_type);
    foreach ($taxonomy_names as $taxonomy_name) {
        $taxonomy = get_taxonomy($taxonomy_name);
        if ($taxonomy->hierarchical && $taxonomy->show_ui) {
            $terms = get_object_term_cache($post->ID, $taxonomy_name);
            if (false === $terms) {
                $terms = wp_get_object_terms($post->ID, $taxonomy_name);
                wp_cache_add($post->ID, wp_list_pluck($terms, 'term_id'), $taxonomy_name . '_relationships');
            }
            $term_ids = empty($terms) ? array() : wp_list_pluck($terms, 'term_id');
            echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode(',', $term_ids) . '</div>';
        } elseif ($taxonomy->show_ui) {
            $terms_to_edit = get_terms_to_edit($post->ID, $taxonomy_name);
            if (!is_string($terms_to_edit)) {
                $terms_to_edit = '';
            }
            echo '<div class="tags_input" id="' . $taxonomy_name . '_' . $post->ID . '">' . esc_html(str_replace(',', ', ', $terms_to_edit)) . '</div>';
        }
    }
    if (!$post_type_object->hierarchical) {
        echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
    }
    if (post_type_supports($post->post_type, 'post-formats')) {
        echo '<div class="post_format">' . esc_html(get_post_format($post->ID)) . '</div>';
    }
    echo '</div>';
}
开发者ID:robbenz,项目名称:plugs,代码行数:65,代码来源:template.php

示例10: is_object_in_term

/**
 * Determine if the given object is associated with any of the given terms.
 *
 * The given terms are checked against the object's terms' term_ids, names and slugs.
 * Terms given as integers will only be checked against the object's terms' term_ids.
 * If no terms are given, determines if object is associated with any terms in the given taxonomy.
 *
 * @since 2.7.0
 *
 * @param int              $object_id ID of the object (post ID, link ID, ...).
 * @param string           $taxonomy  Single taxonomy name.
 * @param int|string|array $terms     Optional. Term term_id, name, slug or array of said. Default null.
 * @return bool|WP_Error WP_Error on input error.
 */
function is_object_in_term($object_id, $taxonomy, $terms = null)
{
    if (!($object_id = (int) $object_id)) {
        return new WP_Error('invalid_object', __('Invalid object ID'));
    }
    $object_terms = get_object_term_cache($object_id, $taxonomy);
    if (false === $object_terms) {
        $object_terms = wp_get_object_terms($object_id, $taxonomy, array('update_term_meta_cache' => false));
        wp_cache_set($object_id, $object_terms, "{$taxonomy}_relationships");
    }
    if (is_wp_error($object_terms)) {
        return $object_terms;
    }
    if (empty($object_terms)) {
        return false;
    }
    if (empty($terms)) {
        return !empty($object_terms);
    }
    $terms = (array) $terms;
    if ($ints = array_filter($terms, 'is_int')) {
        $strs = array_diff($terms, $ints);
    } else {
        $strs =& $terms;
    }
    foreach ($object_terms as $object_term) {
        // If term is an int, check against term_ids only.
        if ($ints && in_array($object_term->term_id, $ints)) {
            return true;
        }
        if ($strs) {
            // Only check numeric strings against term_id, to avoid false matches due to type juggling.
            $numeric_strs = array_map('intval', array_filter($strs, 'is_numeric'));
            if (in_array($object_term->term_id, $numeric_strs, true)) {
                return true;
            }
            if (in_array($object_term->name, $strs)) {
                return true;
            }
            if (in_array($object_term->slug, $strs)) {
                return true;
            }
        }
    }
    return false;
}
开发者ID:n8maninger,项目名称:WordPress,代码行数:60,代码来源:taxonomy-functions.php

示例11: get_attachment_fields_to_edit

/**
 * {@internal Missing Short Description}}
 *
 * @since unknown
 *
 * @param unknown_type $post
 * @param unknown_type $errors
 * @return unknown
 */
function get_attachment_fields_to_edit($post, $errors = null)
{
    if (is_int($post)) {
        $post =& get_post($post);
    }
    if (is_array($post)) {
        $post = (object) $post;
    }
    $image_url = wp_get_attachment_url($post->ID);
    $edit_post = sanitize_post($post, 'edit');
    $form_fields = array('post_title' => array('label' => __('Title'), 'value' => $edit_post->post_title), 'post_excerpt' => array('label' => __('Caption'), 'value' => $edit_post->post_excerpt), 'post_content' => array('label' => __('Description'), 'value' => $edit_post->post_content, 'input' => 'textarea'), 'url' => array('label' => __('Link URL'), 'input' => 'html', 'html' => image_link_input_fields($post, get_option('image_default_link_type')), 'helps' => __('Enter a link URL or click above for presets.')), 'menu_order' => array('label' => __('Order'), 'value' => $edit_post->menu_order), 'image_url' => array('label' => __('File URL'), 'input' => 'html', 'html' => "<input type='text' class='urlfield' readonly='readonly' name='attachments[{$post->ID}][url]' value='" . esc_attr($image_url) . "' /><br />", 'value' => isset($edit_post->post_url) ? $edit_post->post_url : '', 'helps' => __('Location of the uploaded file.')));
    foreach (get_attachment_taxonomies($post) as $taxonomy) {
        $t = (array) get_taxonomy($taxonomy);
        if (empty($t['label'])) {
            $t['label'] = $taxonomy;
        }
        if (empty($t['args'])) {
            $t['args'] = array();
        }
        $terms = get_object_term_cache($post->ID, $taxonomy);
        if (empty($terms)) {
            $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
        }
        $values = array();
        foreach ($terms as $term) {
            $values[] = $term->name;
        }
        $t['value'] = join(', ', $values);
        $form_fields[$taxonomy] = $t;
    }
    // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
    // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
    $form_fields = array_merge_recursive($form_fields, (array) $errors);
    $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);
    return $form_fields;
}
开发者ID:Alenjandro,项目名称:data-my-share,代码行数:45,代码来源:media.php

示例12: get_terms_to_edit

/**
 * Get comma-separated list of terms available to edit for the given post ID.
 *
 * @since 2.8.0
 *
 * @param int    $post_id
 * @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
 * @return string|bool|WP_Error
 */
function get_terms_to_edit($post_id, $taxonomy = 'post_tag')
{
    $post_id = (int) $post_id;
    if (!$post_id) {
        return false;
    }
    $terms = get_object_term_cache($post_id, $taxonomy);
    if (false === $terms) {
        $terms = wp_get_object_terms($post_id, $taxonomy);
        wp_cache_add($post_id, $terms, $taxonomy . '_relationships');
    }
    if (!$terms) {
        return false;
    }
    if (is_wp_error($terms)) {
        return $terms;
    }
    $term_names = array();
    foreach ($terms as $term) {
        $term_names[] = $term->name;
    }
    $terms_to_edit = esc_attr(join(',', $term_names));
    /**
     * Filter the comma-separated list of terms available to edit.
     *
     * @since 2.8.0
     *
     * @see get_terms_to_edit()
     *
     * @param array  $terms_to_edit An array of terms.
     * @param string $taxonomy     The taxonomy for which to retrieve terms. Default 'post_tag'.
     */
    $terms_to_edit = apply_filters('terms_to_edit', $terms_to_edit, $taxonomy);
    return $terms_to_edit;
}
开发者ID:nstungxd,项目名称:F2CA5,代码行数:44,代码来源:taxonomy.php

示例13: lazyload_term_meta

 /**
  * Lazy-loads termmeta for located posts.
  * As a rule, term queries (`get_terms()` and `wp_get_object_terms()`) prime the metadata cache for matched
  * terms by default. However, this can cause a slight performance penalty, especially when that metadata is
  * not actually used. In the context of a `WP_Query` instance, we're able to avoid this potential penalty.
  * `update_object_term_cache()`, called from `update_post_caches()`, does not 'update_term_meta_cache'.
  * Instead, the first time `get_term_meta()` is called from within a `WP_Query` loop, the current method
  * detects the fact, and then primes the metadata cache for all terms attached to all posts in the loop,
  * with a single database query.
  * This method is public so that it can be used as a filter callback. As a rule, there is no need to invoke it
  * directly, from either inside or outside the `WP_Query` object.
  * @param mixed $check  The `$check` param passed from the 'get_term_metadata' hook.
  * @param int  $term_id ID of the term whose metadata is being cached.
  * @return mixed In order not to short-circuit `get_metadata()`. Generally, this is `null`, but it could be
  *               another value if filtered by a plugin.
  */
 public function lazyload_term_meta($check, $term_id)
 {
     /*
      * We only do this once per `WP_Query` instance.
      * Can't use `remove_filter()` because of non-unique object hashes.
      */
     if ($this->updated_term_meta_cache) {
         return $check;
     }
     // We can only lazyload if the entire post object is present.
     $posts = array();
     foreach ($this->posts as $post) {
         if ($post instanceof WP_Post) {
             $posts[] = $post;
         }
     }
     if (!empty($posts)) {
         // Fetch cached term_ids for each post. Keyed by term_id for faster lookup.
         $term_ids = array();
         foreach ($posts as $post) {
             $taxonomies = get_object_taxonomies($post->post_type);
             foreach ($taxonomies as $taxonomy) {
                 // Term cache should already be primed by 'update_post_term_cache'.
                 $terms = get_object_term_cache($post->ID, $taxonomy);
                 if (false !== $terms) {
                     foreach ($terms as $term) {
                         if (!isset($term_ids[$term->term_id])) {
                             $term_ids[$term->term_id] = 1;
                         }
                     }
                 }
             }
         }
         /*
          * Only update the metadata cache for terms belonging to these posts if the term_id passed
          * to `get_term_meta()` matches one of those terms. This prevents a single call to
          * `get_term_meta()` from priming metadata for all `WP_Query` objects.
          */
         if (isset($term_ids[$term_id])) {
             update_termmeta_cache(array_keys($term_ids));
             $this->updated_term_meta_cache = true;
         }
     }
     // If no terms were found, there's no need to run this again.
     if (empty($term_ids)) {
         $this->updated_term_meta_cache = true;
     }
     return $check;
 }
开发者ID:AppItNetwork,项目名称:yii2-wordpress-themes,代码行数:65,代码来源:WP_Query.php

示例14: get_the_tags

function get_the_tags($id = 0)
{
    global $post;
    $id = (int) $id;
    if (!$id && !in_the_loop()) {
        return false;
    }
    // in-the-loop function
    if (!$id) {
        $id = (int) $post->ID;
    }
    $tags = get_object_term_cache($id, 'post_tag');
    if (false === $tags) {
        $tags = wp_get_object_terms($id, 'post_tag');
    }
    $tags = apply_filters('get_the_tags', $tags);
    if (empty($tags)) {
        return false;
    }
    return $tags;
}
开发者ID:helmonaut,项目名称:owb-mirror,代码行数:21,代码来源:category-template.php

示例15: get_the_terms

/**
 * Retrieve the terms of the taxonomy that are attached to the post.
 *
 * This function can only be used within the loop.
 *
 * @since 2.5.0
 *
 * @param int $id Post ID. Is not optional.
 * @param string $taxonomy Taxonomy name.
 * @return array|bool False on failure. Array of term objects on success.
 */
function get_the_terms($id = 0, $taxonomy)
{
    global $post;
    $id = (int) $id;
    if (!$id && !in_the_loop()) {
        return false;
    }
    // in-the-loop function
    if (!$id) {
        $id = (int) $post->ID;
    }
    $terms = get_object_term_cache($id, $taxonomy);
    if (false === $terms) {
        $terms = wp_get_object_terms($id, $taxonomy);
    }
    if (empty($terms)) {
        return false;
    }
    return $terms;
}
开发者ID:papayalabs,项目名称:htdocs,代码行数:31,代码来源:category-template.php


注:本文中的get_object_term_cache函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。