本文整理汇总了PHP中get_the_terms函数的典型用法代码示例。如果您正苦于以下问题:PHP get_the_terms函数的具体用法?PHP get_the_terms怎么用?PHP get_the_terms使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_the_terms函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: new_question
/**
* Add activity after inserting new question.
* @param integer $question_id Post ID.
*/
public function new_question($question_id)
{
$question = get_post($question_id);
$question_title = '<a class="ap-q-link" href="' . wp_get_shortlink($question_id) . '">' . get_the_title($question_id) . '</a>';
$txo_type = '';
if (taxonomy_exists('question_category')) {
$txo_type = 'question_category';
}
if (taxonomy_exists('question_tag')) {
$txo_type = 'question_tag';
}
$term_ids = array();
if (!empty($txo_type)) {
$terms = get_the_terms($question_id, $txo_type);
if ($terms) {
foreach ($terms as $t) {
$term_ids[] = $t->term_id;
}
$term_ids = implode(',', $term_ids);
}
}
$activity_arr = array('user_id' => $question->post_author, 'type' => 'new_question', 'question_id' => $question_id, 'permalink' => wp_get_shortlink($question_id), 'content' => sprintf(__('%s asked question %s', 'anspress-question-answer'), ap_activity_user_name($question->post_author), $question_title), 'term_ids' => $term_ids);
$activity_id = ap_new_activity($activity_arr);
// Add question activity meta.
update_post_meta($question_id, '__ap_activity', array('type' => 'new_question', 'user_id' => $question->post_author, 'date' => current_time('mysql')));
$this->check_mentions($question_id, $question->post_content, $question_title, $question->post_author, __('question', 'anspress-question-answer'));
// Notify users.
// ap_new_notification($activity_id, $question->post_author);
}
示例2: manage_events_columns
function manage_events_columns($name)
{
global $post, $wp_query, $default_date;
switch ($name) {
case 'events_cat':
$terms = get_the_terms($post->ID, 'events_cat');
//If the terms array contains items... (dupe of core)
if (!empty($terms)) {
//Loop through terms
foreach ($terms as $term) {
//Add tax name & link to an array
$post_terms[] = esc_html(sanitize_term_field('name', $term->name, $term->term_id, '', 'edit'));
}
//Spit out the array as CSV
echo implode(', ', $post_terms);
} else {
//Text to show if no terms attached for post & tax
echo '<em>No terms</em>';
}
break;
case 'eventdate':
if (get_post_meta(get_the_ID(), 'event_date', true) != '') {
echo date($default_date, get_post_meta(get_the_ID(), 'event_date', true));
}
//echo get_post_meta( get_the_ID(),'event_date',TRUE );
break;
case 'location':
echo get_post_meta(get_the_ID(), 'event_location', TRUE);
break;
case 'venue':
echo get_post_meta(get_the_ID(), 'event_venue', TRUE);
break;
}
}
示例3: lazyLoadProperty
protected function lazyLoadProperty($key)
{
switch ($key) {
case 'page_template':
return $this->page_template = get_post_meta($this->ID, '_wp_page_template', true);
case 'post_category':
if (is_object_in_taxonomy($this->post_type, 'category')) {
$terms = get_the_terms($this->ID, 'category');
if (empty($terms)) {
$this->post_category = array();
} else {
$this->post_category = wp_list_pluck($terms, 'term_id');
}
}
return $this->post_category;
case 'tags_input':
if (is_object_in_taxonomy($this->post_type, 'post_tag')) {
$terms = get_the_terms($this->ID, 'post_tag');
if (empty($terms)) {
$this->tags_input = array();
} else {
$this->tags_input = wp_list_pluck($terms, 'name');
}
}
return $this->tags_input;
case 'ancestors':
return $this->ancestors = get_post_ancestors($this);
default:
break;
}
throw new \InvalidArgumentException("Invalid lazy-loaded property '{$key}'");
}
示例4: todays_movies
function todays_movies()
{
$todays_movies = array();
$args = array('post_type' => array('film'), 'posts_per_page' => -1);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$schedule = get_post_meta(get_the_ID(), 'film_horaire', true);
$duration = get_post_meta(get_the_ID(), 'film_duration', true);
//the_title();
//piklist::pre($schedule);
foreach ($schedule as $key) {
//echo $key['film_date'] . '<br>';
$movie_iso_date = DateTime::createFromFormat('d/m/Y', $key['film_date'])->format('Y-m-d');
//echo $movie_iso_date . '<br>';
if (date('Y-m-d') == $movie_iso_date) {
$director = get_the_terms($post->ID, 'director');
$countries = get_the_terms($post->ID, 'country');
$languages = get_the_terms($post->ID, 'language');
$year = get_the_terms($post->ID, 'film-year');
$format = get_the_terms($post->ID, 'format');
$featured_image = wp_get_attachment_url(get_post_thumbnail_id(get_the_ID()));
$film_detail = array('id' => get_the_ID(), 'image' => $featured_image, 'title' => get_the_title(), 'duration' => $duration, 'excerpt' => get_the_excerpt(), 'link' => get_permalink(), 'date' => $movie_iso_date, 'hour' => $key['film_heure'], 'director' => $director, 'country' => $countries, 'language' => $languages, 'year' => $year, 'format' => $format);
array_push($todays_movies, $film_detail);
}
}
}
wp_reset_postdata();
}
return $todays_movies;
}
示例5: ap_question_categories_html
function ap_question_categories_html($post_id = false, $list = true)
{
if (!ap_opt('enable_categories')) {
return;
}
if (!$post_id) {
$post_id = get_the_ID();
}
$cats = get_the_terms($post_id, 'question_category');
if ($cats) {
if ($list) {
$o = '<ul class="question-categories">';
foreach ($cats as $c) {
$o .= '<li><a href="' . esc_url(get_term_link($c)) . '" title="' . $c->description . '">' . $c->name . '</a></li>';
}
$o .= '</ul>';
echo $o;
} else {
$o = 'Categories:';
$o .= ' <span class="question-categories-list">';
foreach ($cats as $c) {
$o .= '<a href="' . esc_url(get_term_link($c)) . '" title="' . $c->description . '">' . $c->name . '</a>';
}
$o .= '</span>';
echo $o;
}
}
}
示例6: filter_available_payment_gateways_per_category
/**
* filter_available_payment_gateways_per_category.
*/
function filter_available_payment_gateways_per_category($available_gateways)
{
//if ( ! is_checkout() ) return $available_gateways;
foreach ($available_gateways as $gateway_id => $gateway) {
$categories_in = get_option('wcj_gateways_per_category_' . $gateway_id);
if (!empty($categories_in)) {
$do_skip = true;
foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
$product_categories = get_the_terms($values['product_id'], 'product_cat');
if (empty($product_categories)) {
continue;
}
// ... to next product in the cart
foreach ($product_categories as $product_category) {
if (in_array($product_category->term_id, $categories_in)) {
// Current gateway is OK, breaking to check next gateway (no need to check other categories of the product)
$do_skip = false;
break;
}
}
if (!$do_skip) {
// Current gateway is OK, breaking to check next gateway (no need to check other products in the cart)
break;
}
}
if ($do_skip) {
// Skip (i.e. hide/unset) current gateway - no products of needed categories found in the cart
unset($available_gateways[$gateway_id]);
}
}
}
return $available_gateways;
}
示例7: ubik_places_ancestors
function ubik_places_ancestors($taxonomy = 'places', $depth = 2, $sep = ', ')
{
// Initialize
$output = '';
$places = array();
// Get term ID; we only need one
global $post;
$terms = get_the_terms($post->ID, $taxonomy);
$term = $terms[0];
// Only proceed if this term shows inheritance
if (!empty($term->parent)) {
// The grunt work
$ancestors = ubik_terms_ancestors($term->term_id, $taxonomy);
// Ready to roll
if (!empty($ancestors) && count($ancestors) > 1) {
// Remove basal term, limit depth, and reverse (as is the custom for displaying places)
$ancestors = array_reverse(array_slice(array_slice($ancestors, 0, -1), 0, $depth));
// Loop through all ancestors and create links
if (!empty($ancestors)) {
foreach ($ancestors as $ancestor) {
$place = get_term_by('id', $ancestor, $taxonomy);
$places[] = '<a href="' . get_term_link($place->term_id, $taxonomy) . '" rel="tag">' . $place->name . '</a>';
}
// Assemble output
if (!empty($places)) {
$output = implode($sep, $places);
}
}
}
}
return $output;
}
示例8: custom_columns_portfolio
function custom_columns_portfolio($column)
{
global $post;
switch ($column) {
case "portfolio_image":
if (has_post_thumbnail()) {
$imageurl = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
?>
<img src="<?php
echo $imageurl;
?>
" height="120" />
<?php
}
break;
case "pcategories":
$pcategories = get_the_terms(0, "portfolios");
$pcategories_html = array();
if ($pcategories) {
foreach ($pcategories as $pcategory) {
array_push($pcategories_html, $pcategory->name);
}
echo implode($pcategories_html, ", ");
}
break;
}
}
示例9: delete_cache_transition
function delete_cache_transition($new_status, $old_status, $post)
{
global $wpdb;
$cache_duration = vibe_get_option('cache_duration');
if (!isset($cache_duration)) {
$cache_duration = 0;
}
if ($cache_duration) {
$key = 'kposts_' . $post->post_type;
$instructor_content_privacy = vibe_get_option('instructor_content_privacy');
if ($instructor_content_privacy) {
$user_id = get_current_user_id();
$key .= '_' . $user_id;
}
$linkage = vibe_get_option('linkage');
if (isset($linkage) && $linkage) {
$linkage_terms = get_the_terms($post_id, 'linkage');
if (isset($linkage_terms) && is_array($linkage_terms)) {
foreach ($linkage_terms as $term) {
$key .= '_' . $term->name;
}
}
}
delete_transient($key);
if ($post->post_type == 'course') {
global $wpdb;
$wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '%wplms_%_course%'");
}
}
}
示例10: get_related_projects
function get_related_projects($post_id, $number_posts = 8) {
$query = new WP_Query();
$args = '';
if($number_posts == 0) {
return $query;
}
$item_cats = get_the_terms($post_id, 'portfolio_category');
if($item_cats):
foreach($item_cats as $item_cat) {
$item_array[] = $item_cat->term_id;
}
endif;
$args = wp_parse_args($args, array(
'posts_per_page' => $number_posts,
'post__not_in' => array($post_id),
'ignore_sticky_posts' => 0,
'meta_key' => '_thumbnail_id',
'post_type' => 'avada_portfolio',
'tax_query' => array(
array(
'taxonomy' => 'portfolio_category',
'field' => 'id',
'terms' => $item_array
)
)
));
$query = new WP_Query($args);
return $query;
}
示例11: cause_columns
function cause_columns($name)
{
global $post;
switch ($name) {
case 'category':
$categories = get_the_terms($post->ID, 'cs_cause-category');
if ($categories != "") {
$couter_comma = 0;
foreach ($categories as $category) {
echo $category->name;
$couter_comma++;
if ($couter_comma < count($categories)) {
echo ", ";
}
}
}
break;
case 'tag':
$categories = get_the_terms($post->ID, 'cs_cause-tag');
if ($categories != "") {
$couter_comma = 0;
foreach ($categories as $category) {
echo $category->name;
$couter_comma++;
if ($couter_comma < count($categories)) {
echo ", ";
}
}
}
break;
case 'author':
echo get_the_author();
break;
}
}
示例12: custom_columns
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns($column, $post_id)
{
switch ($column) {
case 'sp_league':
echo get_the_terms($post_id, 'sp_league') ? the_terms($post_id, 'sp_league') : __('All', 'prosports');
break;
case 'sp_season':
echo get_the_terms($post_id, 'sp_season') ? the_terms($post_id, 'sp_season') : __('All', 'prosports');
break;
case 'sp_team':
$teams = (array) get_post_meta($post_id, 'sp_team', false);
$teams = array_filter($teams);
if (empty($teams)) {
_e('All', 'prosports');
} else {
foreach ($teams as $team_id) {
if (!$team_id) {
continue;
}
$team = get_post($team_id);
if ($team) {
echo $team->post_title . '<br>';
}
}
}
break;
}
}
示例13: output
/**
* Output the metabox
*/
public static function output($post)
{
$player = new SP_Player($post);
$leagues = get_the_terms($post->ID, 'sp_league');
$league_num = sizeof($leagues);
// Loop through statistics for each league
if ($leagues) {
$i = 0;
foreach ($leagues as $league) {
?>
<p><strong><?php
echo $league->name;
?>
</strong></p>
<?php
list($columns, $data, $placeholders, $merged, $seasons_teams) = $player->data($league->term_id, true);
self::table($post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $i == 0);
$i++;
}
}
?>
<p><strong><?php
_e('Career Total', 'sportspress');
?>
</strong></p>
<?php
list($columns, $data, $placeholders, $merged, $seasons_teams) = $player->data(0, true);
self::table($post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams);
}
示例14: orbit_manage_excpt2_columns
function orbit_manage_excpt2_columns($column, $post_id)
{
global $post;
switch ($column) {
// If displaying the 'type' column
case 'type':
// Get the types for the post
$terms = get_the_terms($post_id, 'excpt2-type');
// If terms were found
if (!empty($terms)) {
$out = array();
// Loop through each term, linking to the 'edit posts' page for the specific term
foreach ($terms as $term) {
$out[] = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('post_type' => $post->post_type, 'excpt2' => $term->slug), 'edit.php')), esc_html(sanitize_term_field('name', $term->name, $term->term_id, 'excpt2', 'display')));
}
// Join the terms, separating them with a comma
echo join(', ', $out);
} else {
_e('No excpt2 type');
}
break;
// Just break out of the switch statement for everything else
// Just break out of the switch statement for everything else
default:
break;
}
}
示例15: ceo_comic_archive_jump_to_chapter
function ceo_comic_archive_jump_to_chapter($hide = true, $exclude = '', $showcount = false, $jumptoarchive = false, $echo = true, $render_as_list = false)
{
ceo_protect();
$output = '';
if ($render_as_list) {
global $post;
$the_terms = get_the_terms($post->ID, 'chapters');
// echo "<pre>the terms ";print_r($the_terms); echo "</pre>";
$args = array('walker' => new ceo_walker_taxonomy_list(), 'orderby' => 'menu_order', 'order' => 'ASC', 'show_count' => $showcount, 'hide_empty' => $hide, 'exclude' => $exclude, 'echo' => false, 'hierarchical' => 1, 'taxonomy' => 'chapters', 'current_category' => $the_terms, 'title_li' => null, 'jumptoarchive' => $jumptoarchive, 'render_as_list' => $render_as_list);
$output .= '<ul class="chapter-select">';
$output .= wp_list_categories($args);
$output .= '</ul>';
} else {
$args = array('walker' => new ceo_walker_taxonomy_dropdown(), 'show_option_all' => __('Select', 'comiceasel') . ' ' . ucwords(ceo_pluginfo('chapter_type_slug_name')), 'option_none_value' => '-1', 'orderby' => 'menu_order', 'order' => 'ASC', 'name' => ceo_pluginfo('chapter_type_slug_name'), 'show_count' => $showcount, 'hide_empty' => $hide, 'exclude' => $exclude, 'echo' => false, 'hierarchical' => 1, 'taxonomy' => 'chapters', 'hide_if_empty' => $hide, 'value_field' => 'slug', 'jumptoarchive' => $jumptoarchive, 'render_as_list' => $render_as_list);
$output .= '<form id="chapter-select" class="chapter-select" method="get">' . "\r\n";
$select = wp_dropdown_categories($args);
$replace = '<select$1 onchange="document.location.href=this.options[this.selectedIndex].value;">';
$output .= preg_replace('#<select([^>]*)>#', $replace, $select);
$output .= "\t<noscript>\r\n";
$output .= "\t\t<input type=\"submit\" value=\"View\" />\r\n";
$output .= "\t</noscript>\r\n";
$output .= "</form>\r\n";
}
ceo_unprotect();
if ($echo) {
echo $output;
} else {
return $output;
}
}