• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP get_object_term_cache函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: get_the_terms_silently

 static function get_the_terms_silently($post_id = 0, $taxonomy = '')
 {
     if (empty($post_id)) {
         $post_id = get_the_ID();
     }
     if (empty($post_id) || empty($taxonomy)) {
         return false;
     }
     $terms = get_object_term_cache($post_id, $taxonomy);
     if (false === $terms) {
         $terms = wp_get_object_terms($post_id, $taxonomy);
         if ($terms instanceof WP_Error) {
             return false;
         }
     }
     return get_the_terms($post_id, $taxonomy);
 }
开发者ID:surreal8,项目名称:wptheme,代码行数:17,代码来源:content.php


示例17: get_object_term

 protected function get_object_term($object_id, $taxonomy)
 {
     $term = get_object_term_cache($object_id, $taxonomy);
     if (false === $term) {
         // query language and translations at the same time
         $taxonomies = false !== strpos($taxonomy, 'term_') ? array('term_language', 'term_translations') : array('language', 'post_translations');
         foreach (wp_get_object_terms($object_id, $taxonomies) as $t) {
             wp_cache_add($object_id, array($t), $t->taxonomy . '_relationships');
             // store it the way WP wants it
             if ($t->taxonomy == $taxonomy) {
                 $term = $t;
             }
         }
     } else {
         $term = reset($term);
     }
     return empty($term) ? false : $term;
 }
开发者ID:kivivuori,项目名称:jotain,代码行数:18,代码来源:model.php


示例18: mla_prepare_bulk_edits


//.........这里部分代码省略.........
                 $tax_action = 'replace';
             }
             self::mla_debug_add("mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) terms = " . var_export($terms, true), MLA::MLA_DEBUG_CATEGORY_AJAX);
             /*
              * Ignore empty updates
              */
             if ($hierarchical = is_array($terms)) {
                 if (false !== ($index = array_search(0, $terms))) {
                     unset($terms[$index]);
                 }
             } else {
                 /*
                  * Parse out individual terms
                  */
                 $comma = _x(',', 'tag_delimiter', 'media-library-assistant');
                 if (',' !== $comma) {
                     $tags = str_replace($comma, ',', $terms);
                 }
                 $fragments = explode(',', trim($terms, " \n\t\r\v,"));
                 $terms = array();
                 foreach ($fragments as $fragment) {
                     // WordPress encodes special characters, e.g., "&" as HTML entities in term names
                     if (MLATest::$wp_3dot5) {
                         $fragment = _wp_specialchars(trim(stripslashes_deep($fragment)));
                     } else {
                         $fragment = _wp_specialchars(trim(wp_unslash($fragment)));
                     }
                     if (!empty($fragment)) {
                         $terms[] = $fragment;
                     }
                 }
                 // foreach fragment
                 $terms = array_unique($terms);
             }
             if (empty($terms) && 'replace' != $tax_action) {
                 continue;
             }
             $post_terms = get_object_term_cache($post_id, $taxonomy);
             if (false === $post_terms) {
                 $post_terms = wp_get_object_terms($post_id, $taxonomy);
                 wp_cache_add($post_id, $post_terms, $taxonomy . '_relationships');
             }
             $current_terms = array();
             foreach ($post_terms as $new_term) {
                 if ($hierarchical) {
                     $current_terms[$new_term->term_id] = $new_term->term_id;
                 } else {
                     $current_terms[$new_term->name] = $new_term->name;
                 }
             }
             self::mla_debug_add("mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) current_terms = " . var_export($current_terms, true), MLA::MLA_DEBUG_CATEGORY_AJAX);
             if ('add' == $tax_action) {
                 /*
                  * Add new terms; remove existing terms
                  */
                 foreach ($terms as $index => $new_term) {
                     if (isset($current_terms[$new_term])) {
                         unset($terms[$index]);
                     }
                 }
                 $do_update = !empty($terms);
             } elseif ('remove' == $tax_action) {
                 /*
                  * Remove only the existing terms
                  */
                 foreach ($terms as $index => $new_term) {
                     if (!isset($current_terms[$new_term])) {
                         unset($terms[$index]);
                     }
                 }
                 $do_update = !empty($terms);
             } else {
                 /*
                  * Replace all terms; if the new terms match the term
                  * cache, we can skip the update
                  */
                 foreach ($terms as $new_term) {
                     if (isset($current_terms[$new_term])) {
                         unset($current_terms[$new_term]);
                     } else {
                         $current_terms[$new_term] = $new_term;
                         break;
                         // not a match; stop checking
                     }
                 }
                 $do_update = !empty($current_terms);
             }
             self::mla_debug_add("mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) do_update = " . var_export($do_update, true), MLA::MLA_DEBUG_CATEGORY_AJAX);
             self::mla_debug_add("mla_prepare_bulk_edits( {$post_id}, {$taxonomy}, {$tax_action} ) new terms = " . var_export($terms, true), MLA::MLA_DEBUG_CATEGORY_AJAX);
             if ($do_update) {
                 $tax_inputs[$taxonomy] = $terms;
                 $tax_actions[$taxonomy] = $tax_action;
             }
         }
         // foreach taxonomy
     }
     $new_data['tax_input'] = $tax_inputs;
     $new_data['tax_action'] = $tax_actions;
     return $new_data;
 }
开发者ID:n3ssi3,项目名称:tauch-terminal,代码行数:101,代码来源:class-mla-main.php


示例19: get_post

 /**
  * Get a post and associated data in the standard JP format.
  * Cannot be called statically
  *
  * @param int $id Post ID
  * @param bool|array $columns Columns/fields to get.
  * @return Array containing full post details
  */
 function get_post($id, $columns = true)
 {
     $post_obj = get_post($id);
     if (!$post_obj) {
         return false;
     }
     $post = get_object_vars($post_obj);
     // Only send specific columns if requested
     if (is_array($columns)) {
         $keys = array_keys($post);
         foreach ($keys as $column) {
             if (!in_array($column, $columns)) {
                 unset($post[$column]);
             }
         }
         if (in_array('_jetpack_backfill', $columns)) {
             $post['_jetpack_backfill'] = true;
         }
     }
     if (true === $columns || in_array('tax', $columns)) {
         $tax = array();
         $taxonomies = get_object_taxonomies($post_obj);
         foreach ($taxonomies as $taxonomy) {
             $t = get_taxonomy($taxonomy);
             $terms = get_object_term_cache($post_obj->ID, $taxonomy);
             if (empty($terms)) {
                 $terms = wp_get_object_terms($post_obj->ID, $taxonomy);
             }
             $term_names = array();
             foreach ($terms as $term) {
                 $term_names[] = $term->name;
             }
             $tax[$taxonomy] = $term_names;
         }
         $post['tax'] = $tax;
     }
     // Include all postmeta for requests that specifically ask for it, or ask for everything
     if (true == $columns || in_array('meta', $columns)) {
         $meta = get_post_meta($post_obj->ID, false);
         $post['meta'] = array();
         foreach ($meta as $key => $value) {
             $post['meta'][$key] = array_map('maybe_unserialize', $value);
         }
     }
     $post['extra'] = array('author' => get_the_author_meta('display_name', $post_obj->post_author), 'author_email' => get_the_author_meta('email', $post_obj->post_author));
     $post['permalink'] = get_permalink($post_obj->ID);
     return $post;
 }
开发者ID:Bencheci,项目名称:blueRavenStudiosProject,代码行数:56,代码来源:jetpack.php


示例20: get_post

 /**
  * Get a post and associated data in the standard JP format.
  * Cannot be called statically
  *
  * @param int $id Post ID
  * @return Array containing full post details
  */
 function get_post($id)
 {
     $post_obj = get_post($id);
     if (!$post_obj) {
         return false;
     }
     if (is_callable($post_obj, 'to_array')) {
         // WP >= 3.5
         $post = $post_obj->to_array();
     } else {
         // WP < 3.5
         $post = get_object_vars($post_obj);
     }
     if (0 < strlen($post['post_password'])) {
         $post['post_password'] = 'auto-' . wp_generate_password(10, false);
         // We don't want the real password.  Just pass something random.
     }
     // local optimizations
     unset($post['filter'], $post['ancestors'], $post['post_content_filtered'], $post['to_ping'], $post['pinged']);
     if ($this->is_post_public($post)) {
         $post['post_is_public'] = Jetpack_Options::get_option('public');
     } else {
         //obscure content
         $post['post_content'] = '';
         $post['post_excerpt'] = '';
         $post['post_is_public'] = false;
     }
     $post_type_obj = get_post_type_object($post['post_type']);
     $post['post_is_excluded_from_search'] = $post_type_obj->exclude_from_search;
     $post['tax'] = array();
     $taxonomies = get_object_taxonomies($post_obj);
     foreach ($taxonomies as $taxonomy) {
         $terms = get_object_term_cache($post_obj->ID, $taxonomy);
         if (empty($terms)) {
             $terms = wp_get_object_terms($post_obj->ID, $taxonomy);
         }
         $term_names = array();
         foreach ($terms as $term) {
             $term_names[] = $term->name;
         }
         $post['tax'][$taxonomy] = $term_names;
     }
     $meta = get_post_meta($post_obj->ID, false);
     $post['meta'] = array();
     foreach ($meta as $key => $value) {
         $post['meta'][$key] = array_map('maybe_unserialize', $value);
     }
     $post['extra'] = array('author' => get_the_author_meta('display_name', $post_obj->post_author), 'author_email' => get_the_author_meta('email', $post_obj->post_author), 'dont_email_post_to_subs' => get_post_meta($post_obj->ID, '_jetpack_dont_email_post_to_subs', true));
     if ($fid = get_post_thumbnail_id($id)) {
         $feature = wp_get_attachment_image_src($fid, 'large');
         if (!empty($feature[0])) {
             $post['extra']['featured_image'] = $feature[0];
         }
         $attachment = get_post($fid);
         if (!empty($attachment)) {
             $metadata = wp_get_attachment_metadata($fid);
             $post['extra']['post_thumbnail'] = array('ID' => (int) $fid, 'URL' => (string) wp_get_attachment_url($fid), 'guid' => (string) $attachment->guid, 'mime_type' => (string) $attachment->post_mime_type, 'width' => (int) isset($metadata['width']) ? $metadata['width'] : 0, 'height' => (int) isset($metadata['height']) ? $metadata['height'] : 0);
             if (isset($metadata['duration'])) {
                 $post['extra']['post_thumbnail'] = (int) $metadata['duration'];
             }
             /**
              * Filters the Post Thumbnail information returned for a specific post.
              *
              * @since 3.3.0
              *
              * @param array $post['extra']['post_thumbnail'] {
              * 	Array of details about the Post Thumbnail.
              *	@param int ID Post Thumbnail ID.
              *	@param string URL Post thumbnail URL.
              *	@param string guid Post thumbnail guid.
              *	@param string mime_type Post thumbnail mime type.
              *	@param int width Post thumbnail width.
              *	@param int height Post thumbnail height.
              * }
              */
             $post['extra']['post_thumbnail'] = (object) apply_filters('get_attachment', $post['extra']['post_thumbnail']);
         }
     }
     $post['permalink'] = get_permalink($post_obj->ID);
     $post['shortlink'] = wp_get_shortlink($post_obj->ID);
     /**
      * Allow modules to send extra info on the sync post process.
      *
      * @since 2.8.0
      *
      * @param array $args Array of custom data to attach to a post.
      * @param Object $post_obj Object returned by get_post() for a given post ID.
      */
     $post['module_custom_data'] = apply_filters('jetpack_sync_post_module_custom_data', array(), $post_obj);
     return $post;
 }
开发者ID:jordankoschei,项目名称:jordankoschei-dot-com,代码行数:98,代码来源:class.jetpack-sync.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP get_object_type函数代码示例发布时间:2022-05-15
下一篇:
PHP get_object_taxonomies函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap