本文整理汇总了PHP中get_post_taxonomies函数的典型用法代码示例。如果您正苦于以下问题:PHP get_post_taxonomies函数的具体用法?PHP get_post_taxonomies怎么用?PHP get_post_taxonomies使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_post_taxonomies函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: defined
<?php
/**
* Plugin Name: WP-API: Print taxonomy data to posts
* Description: A plugin to print taxonomy data to posts and custom post types, just like in V1 of WP-API.
* Version: 1.0
* Author: Christian Nikkanen
* Author URI: http://christiannikkanen.me
* License: MIT
*/
defined('ABSPATH') or die('No script kiddies please!');
add_action("rest_api_init", function () {
$post_types = get_post_types();
foreach ($post_types as $post_type) {
// loop all post types and add field "terms" to api output.
register_rest_field($post_type, "terms", array("get_callback" => function ($post) {
$taxonomies = get_post_taxonomies($post['id']);
$terms_and_taxonomies = [];
foreach ($taxonomies as $taxonomy_name) {
$terms_and_taxonomies[$taxonomy_name] = wp_get_post_terms($post['id'], $taxonomy_name);
}
return $terms_and_taxonomies;
// return array with taxonomy & term data
}));
}
});
示例2: synchronize_terms
/**
* @param int $original_post_id
* @param string $lang
* @param bool $duplicate sets whether missing terms should be created by duplicating the original term
*/
private function synchronize_terms($original_post_id, $lang, $duplicate)
{
global $wpml_post_translations;
$wpml_post_translations->reload();
$translated_post_id = $wpml_post_translations->element_id_in($original_post_id, $lang);
if ((bool) $translated_post_id === true) {
$taxonomies = get_post_taxonomies($original_post_id);
foreach ($taxonomies as $tax) {
$terms_on_original = wp_get_object_terms($original_post_id, $tax);
if (!$this->sitepress->is_translated_taxonomy($tax)) {
if ($this->sitepress->get_setting('sync_post_taxonomies')) {
// Taxonomy is not translated so we can just copy from the original
foreach ($terms_on_original as $key => $term) {
$terms_on_original[$key] = $term->term_id;
}
wp_set_object_terms($translated_post_id, $terms_on_original, $tax);
}
} else {
/** @var int[] $translated_terms translated term_ids */
$translated_terms = $this->get_translated_term_ids($terms_on_original, $lang, $tax, $duplicate);
wp_set_object_terms($translated_post_id, $translated_terms, $tax);
}
}
}
clean_object_term_cache($original_post_id, get_post_type($original_post_id));
}
示例3: momtaz_get_post_class
/**
* Creates a set of classes for each site entry upon display. Each entry is given the class of
* 'hentry'. Posts are given category, tag, and author classes. Alternate post classes of odd,
* even, and alt are added.
*
* @param string|array $class One or more classes to add to the class list.
* @param int $post_id An optional post ID.
* @return array
* @since 1.1
*/
function momtaz_get_post_class($class = '', $post_id = 0)
{
$classes = array();
// Get post object
$post = get_post($post_id);
if (empty($post)) {
return $classes;
}
// hAtom compliance.
$classes[] = 'hentry';
// Get post context.
$context = momtaz_get_post_context($post_id);
// Merge the classes array with post context.
$classes = array_merge($classes, (array) $context);
// Post taxonomies
$post_taxonomies = get_post_taxonomies($post);
if (!empty($post_taxonomies)) {
foreach ($post_taxonomies as $taxonomy) {
$terms = get_the_terms($post->ID, $taxonomy);
if (!empty($terms)) {
foreach ($terms as $term) {
$classes[] = 'term-' . sanitize_html_class($term->slug, $term->term_id);
}
}
}
}
// Sticky posts.
if (is_home() && !is_paged() && is_sticky($post->ID)) {
$classes[] = 'sticky';
}
// Is this post protected by a password?
if (post_password_required($post)) {
$classes[] = 'post-password-required';
}
// Post alt class.
if (!momtaz_is_the_single($post)) {
static $post_alt = 0;
$classes[] = 'set-' . ++$post_alt;
$classes[] = $post_alt % 2 ? 'odd' : 'even';
}
// Has a custom excerpt?
if (has_excerpt($post)) {
$classes[] = 'has-excerpt';
}
// Custom classes.
if (!empty($class)) {
if (!is_array($class)) {
$class = preg_split('#\\s+#', $class);
}
$classes = array_merge($classes, $class);
}
// Apply the WordPress filters.
$classes = apply_filters('post_class', $classes, $class, $post->ID);
// Apply the Momtaz FW filters.
$classes = apply_filters('momtaz_get_post_class', $classes, $post);
// Removes any duplicate and empty classes.
$classes = array_unique(array_filter($classes));
return $classes;
}
示例4: post_grid_term_slug_list
function post_grid_term_slug_list($post_id)
{
$term_slug_list = '';
$post_taxonomies = get_post_taxonomies($post_id);
foreach ($post_taxonomies as $taxonomy) {
$term_list[] = wp_get_post_terms(get_the_ID(), $taxonomy, array("fields" => "all"));
}
return $term_slug_list;
}
示例5: um_access_category_settings
function um_access_category_settings()
{
global $post, $wp_query, $ultimatemember;
if (is_front_page() || is_home()) {
return;
}
if (is_single() || get_post_taxonomies($post)) {
$taxonomies = get_post_taxonomies($post);
$categories_ids = array();
foreach ($taxonomies as $key => $value) {
$term_list = wp_get_post_terms($post->ID, $value, array("fields" => "ids"));
foreach ($term_list as $term_id) {
array_push($categories_ids, $term_id);
}
}
foreach ($categories_ids as $term => $term_id) {
$opt = get_option("category_{$term_id}");
if (isset($opt['_um_accessible'])) {
switch ($opt['_um_accessible']) {
case 0:
$ultimatemember->access->allow_access = true;
$ultimatemember->access->redirect_handler = false;
// open to everyone
break;
case 1:
if (is_user_logged_in()) {
$ultimatemember->access->redirect_handler = isset($opt['_um_redirect']) ? $opt['_um_redirect'] : site_url();
}
if (!is_user_logged_in()) {
$ultimatemember->access->allow_access = true;
}
break;
case 2:
if (!is_user_logged_in()) {
$ultimatemember->access->redirect_handler = isset($opt['_um_redirect']) && !empty($opt['_um_redirect']) ? $opt['_um_redirect'] : um_get_core_page('login');
}
if (is_user_logged_in() && isset($opt['_um_roles']) && !empty($opt['_um_roles'])) {
if (!in_array(um_user('role'), $opt['_um_roles'])) {
if (is_user_logged_in()) {
$ultimatemember->access->redirect_handler = isset($opt['_um_redirect']) ? $opt['_um_redirect'] : site_url();
}
if (!is_user_logged_in()) {
$ultimatemember->access->redirect_handler = um_get_core_page('login');
}
}
}
}
}
if (is_archive()) {
$ultimatemember->access->allow_access = true;
$ultimatemember->access->redirect_handler = false;
// open to everyone
}
}
}
}
示例6: rcp_is_post_taxonomy_restricted
/**
* Check the provided taxonomy along with the given post id to see if any restrictions are found
*
* @since 2.5
* @param $post_id
* @param $taxonomy
* @param null $user_id
*
* @return int|bool true if tax is restricted, false if user can access, -1 if unrestricted or invalid
*/
function rcp_is_post_taxonomy_restricted($post_id, $taxonomy, $user_id = null)
{
$restricted = -1;
if (current_user_can('edit_post', $post_id)) {
return $restricted;
}
// make sure this post supports the supplied taxonomy
$post_taxonomies = get_post_taxonomies($post_id);
if (!in_array($taxonomy, (array) $post_taxonomies)) {
return $restricted;
}
$terms = get_the_terms($post_id, $taxonomy);
if (empty($terms) || is_wp_error($terms)) {
return $restricted;
}
if (!$user_id) {
$user_id = get_current_user_id();
}
// Loop through the categories and determine if one has restriction options
foreach ($terms as $term) {
$term_meta = rcp_get_term_restrictions($term->term_id);
if (empty($term_meta['paid_only']) && empty($term_meta['subscriptions']) && (empty($term_meta['access_level']) || 'None' == $term_meta['access_level'])) {
continue;
}
$restricted = false;
/** Check that the user has a paid subscription ****************************************************************/
$paid_only = !empty($term_meta['paid_only']);
if ($paid_only && !rcp_is_paid_user($user_id)) {
$restricted = true;
}
/** If restricted to one or more subscription levels, make sure that the user is a member of one of the levels */
$subscriptions = !empty($term_meta['subscriptions']) ? array_map('absint', $term_meta['subscriptions']) : false;
if ($subscriptions && !in_array(rcp_get_subscription_id($user_id), $subscriptions)) {
$restricted = true;
}
/** If restricted to one or more access levels, make sure that the user is a member of one of the levls ********/
$access_level = !empty($term_meta['access_level']) ? absint($term_meta['access_level']) : 0;
if ($access_level > 0 && !rcp_user_has_access($user_id, $access_level)) {
$restricted = true;
}
$match_all = apply_filters('rcp_restricted_taxonomy_term_match_all', false, $post_id, $taxonomy, $user_id);
// if we are matching all terms then it only takes one restricted term to restrict the taxonomy
if ($restricted && $match_all) {
break;
}
// if we are matching any term, then we only need the user to have access to one
if (!$match_all && !$restricted) {
break;
}
}
return apply_filters('rcp_is_post_taxonomy_restricted', $restricted, $taxonomy, $post_id, $user_id);
}
示例7: synchronize_terms
private function synchronize_terms($original_post_id, $lang, $duplicate)
{
global $wpml_post_translations;
$wpml_post_translations->reload();
$translated_post_id = $wpml_post_translations->element_id_in($original_post_id, $lang);
if ((bool) $translated_post_id === true) {
$taxonomies = get_post_taxonomies($original_post_id);
foreach ($taxonomies as $tax) {
$terms_on_original = wp_get_object_terms($original_post_id, $tax);
/** @var int[] $translated_terms translated term_ids */
$translated_terms = $this->get_translated_term_ids($terms_on_original, $lang, $tax, $duplicate);
wp_set_object_terms($translated_post_id, $translated_terms, $tax);
}
}
}
示例8: wpjam_category_post_thumbnail_uri
function wpjam_category_post_thumbnail_uri($post_thumbnail_uri, $post)
{
$post_taxonomies = get_post_taxonomies($post);
if ($post_taxonomies) {
if (in_array('category', $post_taxonomies)) {
$categories = get_the_category($post);
if ($categories) {
foreach ($categories as $category) {
if ($term_thumbnail = get_term_meta($category->term_id, 'thumbnail', true)) {
return $term_thumbnail;
}
}
}
}
}
}
示例9: portfilo_breadcrumbs
function portfilo_breadcrumbs()
{
global $post, $wp_query;
$homeLink = home_url();
$showCurrent = 1;
echo '<div data-wow-delay="1s" class="breadcrum pull-left wow fadeIn animated" style="visibility: visible; animation-delay: 1s; animation-name: fadeIn;">';
echo '<ul>';
echo '<li><a href="' . $homeLink . '"><i class="glyphicon glyphicon-home"></i></a> <span class="breadcrum-sep">/</span></li>';
// Blog Category
if (is_category()) {
echo '<li><span class="active">' . __('Archive by category', 'portfilo') . ' "' . single_cat_title('', false) . '"</span></li>';
} elseif (is_search()) {
echo '<li><span class="active">' . __('Search results for', 'portfilo') . ' "' . get_search_query() . '"</span></li>';
} elseif (is_day()) {
echo '<li><a href="' . get_year_link($wp_query->query_vars['year']) . '">' . $wp_query->query_vars['year'] . '</a> <span class="breadcrum-sep">/</span></li>';
echo '<li><a href="' . get_month_link($wp_query->query_vars['year'], $wp_query->query_vars['monthnum']) . '">' . date_i18n("F", mktime(0, 0, 0, $wp_query->query_vars['monthnum'], 10)) . '</a> <span class="breadcrum-sep">/</span></li>';
echo '<li><span class="active">' . $wp_query->query_vars['day'] . '</span></li>';
} elseif (is_month()) {
echo '<li><a href="' . get_year_link($wp_query->query_vars['year']) . '">' . $wp_query->query_vars['year'] . '</a> <span class="breadcrum-sep">/</span></li>';
echo '<li><span class="active">' . date_i18n("F", mktime(0, 0, 0, $wp_query->query_vars['monthnum'], 10)) . '</span></li>';
} elseif (is_year()) {
echo '<li><span class="active">' . $wp_query->query_vars['year'] . '</span></li>';
} elseif (get_post_type() == 'post') {
$post_for_page_id = get_option('page_for_posts');
echo '<li><a href="' . get_page_link($post_for_page_id) . '">' . get_the_title($post_for_page_id) . '</a></li>';
} elseif (is_single() && !is_attachment()) {
// Custom post type
if (get_post_type() != 'post') {
global $wpdb;
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
if ($slug['slug'] == 'portfolio-item' && ($portfolio_page_id = get_option('portfolio-page'))) {
echo '<li><a href="' . get_page_link($portfolio_page_id) . '">' . get_the_title($portfolio_page_id) . '</a> <span class="breadcrum-sep">/</span></li>';
} else {
echo '<li><a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> <span class="breadcrum-sep">/</span></li>';
}
if ($showCurrent == 1) {
echo '<li><span class="active">' . get_the_title() . '</span></li>';
}
} else {
$cat = get_the_category();
$cat = $cat[0];
echo '<li>';
echo get_category_parents($cat, TRUE, ' <span class="breadcrum-sep">/</span>');
echo '</li>';
echo '<li><span class="active">' . wp_title('', false) . '</span></li>';
}
} elseif (get_post_taxonomies()) {
global $wpdb;
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
if ($post_type->name == 'portfolio' && ($portfolio_page_id = get_option('portfolio-page'))) {
echo '<li><a href="' . get_page_link($portfolio_page_id) . '">' . get_the_title($portfolio_page_id) . '</a> <span class="breadcrum-sep">/</span></li>';
} else {
echo '<li><a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> <span class="breadcrum-sep">/</span></li>';
}
if (is_tax()) {
$terms_object = get_queried_object();
echo '<li><span class="active">' . $terms_object->name . '</span></li>';
}
} elseif (is_page() && $post->post_parent) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '<li><a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a> <span class="breadcrum-sep">/</span></li>';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
for ($i = 0; $i < count($breadcrumbs); $i++) {
echo $breadcrumbs[$i];
}
if ($showCurrent == 1) {
echo '<li><span class="active">' . get_the_title() . '</span></li>';
}
} else {
echo '<li><span class="active">' . get_the_title() . '</span></li>';
}
echo '</ul>';
echo '</div>';
}
示例10: meta_boxes
/**
* Remove the default meta box from the post editing screen and add our custom meta box.
*
* @param string $object_type The object type (eg. the post type)
* @param mixed $object The object (eg. a WP_Post object)
* @return null
*/
function meta_boxes($object_type, $object)
{
if (!is_a($object, 'WP_Post')) {
return;
}
$post_type = $object_type;
$post = $object;
$taxos = get_post_taxonomies($post);
if (in_array($this->taxo->taxonomy, $taxos)) {
$tax = get_taxonomy($this->taxo->taxonomy);
# Remove default meta box:
if ($this->taxo->args['hierarchical']) {
remove_meta_box("{$this->taxo->taxonomy}div", $post_type, 'side');
} else {
remove_meta_box("tagsdiv-{$this->taxo->taxonomy}", $post_type, 'side');
}
if (!current_user_can($tax->cap->assign_terms)) {
return;
}
if ($this->args['meta_box']) {
# Set the 'meta_box' argument to the actual meta box callback function name:
if ('simple' == $this->args['meta_box']) {
if ($this->taxo->args['exclusive']) {
$this->args['meta_box'] = array($this, 'meta_box_radio');
} else {
$this->args['meta_box'] = array($this, 'meta_box_simple');
}
} else {
if ('radio' == $this->args['meta_box']) {
$this->taxo->args['exclusive'] = true;
$this->args['meta_box'] = array($this, 'meta_box_radio');
} else {
if ('dropdown' == $this->args['meta_box']) {
$this->taxo->args['exclusive'] = true;
$this->args['meta_box'] = array($this, 'meta_box_dropdown');
}
}
}
# Add the meta box, using the plural or singular taxonomy label where relevant:
if ($this->taxo->args['exclusive']) {
add_meta_box("{$this->taxo->taxonomy}div", $tax->labels->singular_name, $this->args['meta_box'], $post_type, 'side');
} else {
add_meta_box("{$this->taxo->taxonomy}div", $tax->labels->name, $this->args['meta_box'], $post_type, 'side');
}
} else {
if (false !== $this->args['meta_box']) {
# This must be an 'exclusive' taxonomy. Add the radio meta box:
add_meta_box("{$this->taxo->taxonomy}div", $tax->labels->singular_name, array($this, 'meta_box_radio'), $post_type, 'side');
}
}
}
}
示例11: thematic_postfooter_posttax
/**
* Create the taxonomy list for the post footer
*
* Lists categories, tags, and custom taxonomies
*
* Override: childtheme_override_postfooter_posttax <br>
* Filter: thematic_postfooter_posttax
*/
function thematic_postfooter_posttax()
{
$post_type_tax = get_post_taxonomies();
$post_tax_list = '';
if (isset($post_type_tax) && $post_type_tax) {
foreach ($post_type_tax as $tax) {
if ($tax == 'category') {
$post_tax_list .= thematic_postfooter_postcategory();
} elseif ($tax == 'post_tag') {
$post_tax_list .= thematic_postfooter_posttags();
} else {
$post_tax_list .= thematic_postfooter_postterms($tax);
}
}
}
return apply_filters('thematic_postfooter_posttax', $post_tax_list);
// Filter for default post terms
}
示例12: dp_related_posts
/**
* Related Posts
*
* @since 1.0
*/
function dp_related_posts($args = '')
{
global $post;
$query_args = array();
$defaults = array('view' => 'grid-mini', 'number' => 0, 'fields' => '');
$args = wp_parse_args($args, $defaults);
extract($args);
// Only displayed on singular post pages
if (!is_singular()) {
return;
}
// Check limited number
if (!$number) {
return;
}
// Check taxonomies
$taxes = get_post_taxonomies($post->ID);
if (empty($taxes)) {
return;
}
$taxes = array_unique(array_merge(array('category', 'post_tag'), $taxes));
$in_tax_query_array = array();
$and_tax_query_array = array();
foreach ($taxes as $tax) {
$terms = get_the_terms($post->ID, $tax);
if (empty($terms)) {
continue;
}
$term_ids = array();
foreach ($terms as $term) {
$term_ids[] = $term->term_id;
}
$in_tax_query_array[$tax] = array('taxonomy' => $tax, 'field' => 'id', 'terms' => $term_ids, 'operator' => 'IN');
$and_tax_query_array[$tax] = array('taxonomy' => $tax, 'field' => 'id', 'terms' => $term_ids, 'operator' => 'AND');
}
if (empty($in_tax_query_array) && empty($and_tax_query_array)) {
return;
}
$query_args = array('post_type' => get_post_type($post->ID), 'ignore_sticky_posts' => true, 'posts_per_page' => $number);
$current_post_id = $post->ID;
$found_posts = array();
// Multiple Taxonomy Query: relation = AND, operator = AND
$query_args['tax_query'] = $and_tax_query_array;
$query_args['tax_query']['relation'] = 'AND';
$query_args['post__not_in'] = array($post->ID);
$related = new WP_Query($query_args);
foreach ($related->posts as $post) {
$found_posts[] = $post->ID;
}
// Multiple Taxonomy Query: relation = AND, operator = IN
if (count($found_posts) < $number) {
$query_args['tax_query'] = $in_tax_query_array;
$query_args['tax_query']['relation'] = 'AND';
$query_args['post__not_in'] = array_merge(array($current_post_id), $found_posts);
$related = new WP_Query($query_args);
foreach ($related->posts as $post) {
$found_posts[] = $post->ID;
}
}
// Foreach Each Taxonomy Query: operator = AND
if (count($found_posts) < $number) {
unset($and_tax_query_array['post_format']);
foreach ($and_tax_query_array as $and_tax_query) {
$query_args['tax_query'] = array($and_tax_query);
$query_args['post__not_in'] = array_merge(array($current_post_id), $found_posts);
$related = new WP_Query($query_args);
foreach ($related->posts as $post) {
$found_posts[] = $post->ID;
}
if (count($found_posts) > $number) {
break;
}
}
}
// Foreach Each Taxonomy Query: operator = IN
if (count($found_posts) < $number) {
unset($in_tax_query_array['post_format']);
foreach ($in_tax_query_array as $in_tax_query) {
$query_args['tax_query'] = array($in_tax_query);
$query_args['post__not_in'] = array_merge(array($current_post_id), $found_posts);
$related = new WP_Query($query_args);
foreach ($related->posts as $post) {
$found_posts[] = $post->ID;
}
if (count($found_posts) > $number) {
break;
}
}
}
if (empty($found_posts)) {
return;
}
$query_args['tax_query'] = '';
$query_args['post__in'] = $found_posts;
$related = new WP_Query($query_args);
//.........这里部分代码省略.........
示例13: ci_list_cat_tag_tax
/**
* Returns a string of all the categories, tags and taxonomies the current post is under.
*
* @access public
* @param string $separator
* @return string
*/
function ci_list_cat_tag_tax($separator = ', ')
{
global $post;
$taxonomies = get_post_taxonomies();
$i = 0;
$the_terms = array();
$the_terms_temp = array();
$the_terms_list = '';
foreach ($taxonomies as $taxonomy) {
$the_terms_temp[] = get_the_term_list($post->ID, $taxonomy, '', $separator, '');
}
foreach ($the_terms_temp as $term) {
if (!empty($term)) {
$the_terms[] = $term;
}
}
$terms_count = count($the_terms);
for ($i = 0; $i < $terms_count; $i++) {
$the_terms_list .= $the_terms[$i];
if ($i < $terms_count - 1) {
$the_terms_list .= $separator;
}
}
if (!empty($the_terms_list)) {
return $the_terms_list;
} else {
return __('Uncategorized', 'ci_theme');
}
}
示例14: fusion_adjacent_post_link_plus
//.........这里部分代码省略.........
return get_permalink($post);
case 'object':
return $post;
case 'title':
return $post->post_title;
case 'date':
return mysql2date($r['date_format'], $post->post_date);
}
} elseif ('object' == $r['return']) {
return $posts;
}
}
$output = $r['before'];
// When num_results > 1, multiple adjacent posts may be returned.
// Use foreach to display each adjacent post.
foreach ($posts as $post) {
$title = $post->post_title;
if (empty($post->post_title)) {
$title = $previous ? esc_attr__('Previous Post', 'Avada') : esc_attr__('Next Post', 'Avada');
}
$title = apply_filters('the_title', $title, $post->ID);
$date = mysql2date($r['date_format'], $post->post_date);
$author = get_the_author_meta('display_name', $post->post_author);
// Set anchor title attribute to long post title or custom tooltip text.
// Supports variable replacement in custom tooltip.
$tooltip = '';
if ($r['tooltip']) {
$tooltip = str_replace('%title', $title, $r['tooltip']);
$tooltip = str_replace('%date', $date, $tooltip);
$tooltip = str_replace('%author', $author, $tooltip);
$tooltip = ' title="' . esc_attr($tooltip) . '"';
}
// Truncate the link title to nearest whole word under the length specified.
$max_length = 1 > intval($r['max_length']) ? 9999 : intval($r['max_length']);
if ($max_length < strlen($title)) {
$title = substr($title, 0, strrpos(substr($title, 0, $max_length), ' '));
// mod for LTR larguages.
$title = sprintf(esc_attr__('$s...', 'Avada'), $title);
}
$rel = $previous ? 'prev' : 'next';
$anchor = '<a href="' . get_permalink($post) . '" rel="' . $rel . '"' . $tooltip . '>';
$link = str_replace('%title', $title, $r['link']);
$link = str_replace('%date', $date, $link);
$link = $anchor . $link . '</a>';
$format = str_replace('%link', $link, $r['format']);
$format = str_replace('%title', $title, $format);
$format = str_replace('%date', $date, $format);
$format = str_replace('%author', $author, $format);
if (('custom' == $r['order_by'] || 'numeric' == $r['order_by']) && !empty($r['meta_key'])) {
$meta = get_post_meta($post->ID, $r['meta_key'], true);
$format = str_replace('%meta', $meta, $format);
} elseif ($r['in_same_meta']) {
$meta = get_post_meta($post->ID, $r['in_same_meta'], true);
$format = str_replace('%meta', $meta, $format);
}
// Get the category list, including custom taxonomies
// (only if the %category variable has been used).
if (false !== strpos($format, '%category')) {
$term_list = '';
$taxonomies = array_filter(get_post_taxonomies($post->ID), 'is_taxonomy_hierarchical');
if ($r['in_same_format'] && get_post_format($post->ID)) {
$taxonomies[] = 'post_format';
}
foreach ($taxonomies as &$taxonomy) {
// No, this is not a mistake. Yes, we are testing the result of the assignment ( = ).
// We are doing it this way to stop it from appending a comma when there is no next term.
if ($next_term = get_the_term_list($post->ID, $taxonomy, '', ', ', '')) {
$term_list .= $next_term;
if (current($taxonomies)) {
$term_list .= ', ';
}
}
}
$format = str_replace('%category', $term_list, $format);
}
// Optionally add the post thumbnail to the link.
// Wrap the link in a span to aid CSS styling.
if ($r['thumb'] && has_post_thumbnail($post->ID)) {
if (true === $r['thumb']) {
// use 'post-thumbnail' as the default size
$r['thumb'] = 'post-thumbnail';
}
$thumbnail = '<a class="post-thumbnail" href="' . get_permalink($post) . '" rel="' . $rel . '"' . $tooltip . '>' . get_the_post_thumbnail($post->ID, $r['thumb']) . '</a>';
$format = $thumbnail . '<span class="post-link">' . $format . '</span>';
}
// If more than one link is returned, wrap them in <li> tags
if (1 < intval($r['num_results'])) {
$format = '<li>' . $format . '</li>';
}
$output .= $format;
}
$output .= $r['after'];
// If echo is false, don't display anything. Return the link as a PHP string.
if (!$r['echo'] || 'output' === $r['return']) {
return $output;
}
$adjacent = $previous ? 'previous' : 'next';
echo apply_filters("{$adjacent}_post_link_plus", $output, $r);
return true;
}
示例15: cache_translations
/**
* Cache translated posts
*
* @param $posts
*/
function cache_translations($posts)
{
global $wpdb, $wp_query, $sitepress;
static $last_query = false;
if (defined('WPML_DISABLE_CACHE_TRANSLATIONS') && is_admin()) {
return;
}
if (isset($sitepress) && isset($wp_query) && $wp_query->is_main_query()) {
if ($last_query == $wp_query->query_vars_hash) {
return;
}
$sticky_posts_ids = get_option('sticky_posts');
if ($sticky_posts_ids) {
if (count($sticky_posts_ids) == 1) {
$sticky_posts_prepared = $wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID = %d", array($sticky_posts_ids[0]));
} else {
$sticky_posts_prepared = "SELECT * FROM {$wpdb->posts} WHERE ID IN (" . implode(',', array_filter($sticky_posts_ids)) . ")";
}
$sticky_posts = $wpdb->get_results($sticky_posts_prepared);
$posts_objects = array_map('get_post', $sticky_posts);
if (!$posts) {
$posts = $posts_objects;
} else {
$posts = array_merge($posts, $posts_objects);
//Remove duplicates
$posts = array_map("unserialize", array_unique(array_map("serialize", $posts)));
}
}
if ($posts) {
$terms = array();
//Query specific cache
$cache_key = $wp_query->query_vars_hash;
$cache_group = 'wp_query:posts_translations';
$cached_posts_translations = wp_cache_get($cache_key, $cache_group);
if (!$cached_posts_translations) {
$post_types = array();
foreach ($posts as $post) {
$post_types[$post->post_type][] = $post->ID;
}
$trids = array();
if ($post_types) {
$trid_cache_group = 'element_trid';
foreach ($post_types as $post_type => $posts_ids) {
$element_type = 'post_' . $post_type;
$s_post_type_ids = join(',', array_filter($posts_ids));
$trids_prepared = $wpdb->prepare("SELECT trid, element_id, language_code, source_language_code FROM {$wpdb->prefix}icl_translations WHERE element_id IN (" . $s_post_type_ids . ") AND element_type=%s GROUP BY trid", array($element_type));
$post_type_trids_data = $wpdb->get_results($trids_prepared);
foreach ($post_type_trids_data as $post_type_trid_data) {
$element_id = $post_type_trid_data->element_id;
$trid_cache_key = $element_id . ':post_' . $post_type;
$trid = wp_cache_get($trid_cache_key, $trid_cache_group);
if (!$trid) {
$trid = $post_type_trid_data->trid;
$trids[] = $trid;
wp_cache_add($trid_cache_key, $trid, $trid_cache_group);
}
if ($trid) {
$element_language_details_cache_group = 'element_language_details';
$element_language_details = wp_cache_get($trid_cache_key, $element_language_details_cache_group);
if (!$element_language_details) {
$details = new stdClass();
$details->trid = $trid;
$details->language_code = $post_type_trid_data->language_code;
$details->source_language_code = $post_type_trid_data->source_language_code;
wp_cache_add($trid_cache_key, $details, $element_language_details_cache_group);
}
}
//Deal with taxonomies
//$_taxonomies = get_post_taxonomies($element_id);
$_taxonomies = get_post_taxonomies($element_id);
foreach ($_taxonomies as $_taxonomy) {
if ($sitepress->is_translated_taxonomy($_taxonomy)) {
$_terms = wp_get_post_terms($element_id, $_taxonomy);
foreach ($_terms as $_term) {
$terms[$_term->taxonomy][] = $_term->term_id;
}
}
}
}
}
}
if ($trids) {
if (count($trids) == 1) {
$posts_translations_prepared = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}icl_translations WHERE trid = %d ", array($trids[0]));
} else {
$posts_translations_prepared = "SELECT * FROM {$wpdb->prefix}icl_translations WHERE trid IN (" . join(',', array_filter($trids)) . ") ";
}
$posts_translations = $wpdb->get_results($posts_translations_prepared);
$post_ids = array();
foreach ($posts_translations as $posts_translation) {
$post_ids[] = $posts_translation->element_id;
}
$posts_data = wp_cache_get($cache_key, 'wp_query:posts');
if (!$posts_data && $post_ids) {
$posts_prepared = "SELECT * FROM {$wpdb->posts} WHERE ID IN (" . join(',', array_filter($post_ids)) . ") ";
//.........这里部分代码省略.........