本文整理汇总了PHP中has_term函数的典型用法代码示例。如果您正苦于以下问题:PHP has_term函数的具体用法?PHP has_term怎么用?PHP has_term使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了has_term函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: sv_wc_checkout_add_ons_remove_add_ons_for_giftboxes
/**
* Remove add-ons if _any product_ in the cart is in a given category
* Example: remove add-ons if any product is in the "Gift box" category
*/
function sv_wc_checkout_add_ons_remove_add_ons_for_giftboxes()
{
// bail if Checkout Add-ons isn't active
if (!function_exists('wc_checkout_add_ons')) {
return;
}
// set a flag
$cat_check = false;
// check each cart item for our category
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
$product = $cart_item['data'];
$product_in_cat = false;
// replace 'gift_box' with your category's slug
if (has_term('gift_box', 'product_cat', $product->id)) {
// flag the cart as containing this category, we only need one "true" to break
$cat_check = true;
break;
}
}
// get the position of checkout add-ons so we can remove them properly
$position = get_option('wc_checkout_add_ons_position', 'woocommerce_checkout_after_customer_details');
// if a product in the cart is in our category, remove the add-ons
if ($position && $cat_check) {
remove_action($position, array(wc_checkout_add_ons()->get_frontend_instance(), 'render_add_ons'), 20);
}
}
开发者ID:skyverge,项目名称:wc-plugins-snippets,代码行数:30,代码来源:remove-add-ons-if-any-cart-item-in-category.php
示例2: add_post_to_cat
function add_post_to_cat()
{
// Get the Post ID
if (isset($_POST['post_id']) && !empty($_POST['post_id'])) {
$post_id = esc_html($_POST['post_id']);
} else {
echo json_encode(array('success' => false, 'reason' => 'No Post ID.'));
exit;
}
// Get the Category
if (isset($_POST['cat_id']) && !empty($_POST['cat_id'])) {
$cat_id = esc_html($_POST['cat_id']);
} else {
echo json_encode(array('success' => false, 'reason' => 'No Cat ID.'));
exit;
}
// Check if Post is already in this category
if (has_term($cat_id, 'bookmark-category', $post_id)) {
echo json_encode(array('success' => true, 'reason' => 'duplicate'));
exit;
}
// Add Post to Bookmark Category
$did_add_cat = wp_set_post_terms($post_id, $cat_id, 'bookmark-category', true);
if ($did_add_cat) {
echo json_encode(array('success' => true, 'reason' => 'inserted'));
} else {
echo json_encode(array('success' => false, 'reason' => "Couldn't add cat."));
}
exit;
}
开发者ID:ryan-frankel,项目名称:nerdmash,代码行数:30,代码来源:ajax-add-cat-to-post.php
示例3: add_custom_field_to_comment_form
function add_custom_field_to_comment_form()
{
//Check case single
if (!is_singular('cases')) {
return;
}
if (has_term('', 'results')) {
?>
<div class="toggle_case_result close_case">
<input type="checkbox" id="openCase" name="case_reset_result_cp" value="openCase">
<label for="openCase">Возобновить дело</label>
</div>
<?php
} else {
?>
<div class="toggle_case_result open_case">
<input type="checkbox" id="close_case_cp" name="close_case_comment_cp" value="1">
<label for="close_case_cp">Закрыть дело</label>
<div id="result_select_container"><span>Укажите результат:</span>
<?php
wp_dropdown_categories('taxonomy=results&hide_empty=0&name=case_result_select&id=result_select&hide_if_empty=true');
?>
</div>
</div>
<?php
}
}
开发者ID:systemo-biz,项目名称:casepress-select-result-in-comment,代码行数:27,代码来源:close_case_in_comment.php
示例4: add_blog_automatically
function add_blog_automatically($post_ID)
{
global $wpdb;
if (!has_term('', 'blog_categoria', $post_ID)) {
$cat = 'blog';
wp_set_object_terms($post_ID, $cat, 'blog_categoria');
}
}
开发者ID:Jehny,项目名称:wp_cgf,代码行数:8,代码来源:functions.php
示例5: register_txn_trail_story
function register_txn_trail_story()
{
$labels = array('name' => _x('Trail Story Category', 'trail-story-category'), 'singular_name' => _x('Trail Story Category', 'trail-story-category'), 'search_items' => _x('Search Trail Story Categories', 'trail-story-category'), 'popular_items' => _x('Popular Trail Story Categories', 'trail-story-category'), 'all_items' => _x('All Trail Story Categories', 'trail-story-category'), 'parent_item' => _x('Parent Trail Story Category', 'trail-story-category'), 'parent_item_colon' => _x('Parent Trail Story Category:', 'trail-story-category'), 'edit_item' => _x('Edit Trail Story Category', 'trail-story-category'), 'update_item' => _x('Update Trail Story Category', 'trail-story-category'), 'add_new_item' => _x('Add New', 'trail-story-category'), 'new_item_name' => _x('New Trail Story Category', 'trail-story-category'), 'separate_items_with_commas' => _x('Separate Trail Story Categories with commas', 'trail-story-category'), 'add_or_remove_items' => _x('Add or remove Trail Story Categories', 'trail-story-category'), 'choose_from_most_used' => _x('Choose from the most used Trail Story Category', 'trail-story-category'), 'menu_name' => _x('Categories', 'trail-story-category'));
$args = array('labels' => $labels, 'public' => true, 'show_in_nav_menus' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_tagcloud' => true, 'show_admin_column' => true, 'hierarchical' => true, 'rewrite' => array('slug' => 'story-category'), 'query_var' => true);
register_taxonomy('trail-story-category', array('trail-story'), $args);
if (!has_term('iata-stories', 'trail-story-category')) {
wp_insert_term('Trail Stories', 'trail-story-category', array('User Submitted Trail Stories', 'iata-stories'));
}
}
开发者ID:amgxyz,项目名称:geocms-custom-maps,代码行数:9,代码来源:cpt-trail-story.php
示例6: add_wikipedia_category_automatically
function add_wikipedia_category_automatically($post_ID)
{
global $wpdb;
if (!has_term('', 'category', $post_ID)) {
$category = get_term_by('slug', 'cat-00-02', 'category');
$cat = array($category->term_id);
wp_set_object_terms($post_ID, $cat, 'category');
}
}
开发者ID:rhaubt,项目名称:Rock-Art-Database-RADB-,代码行数:9,代码来源:functions.php
示例7: woo_custom_cart_button_text
function woo_custom_cart_button_text()
{
global $product;
if (has_term('credit', 'product_cat', $product->ID)) {
return __('Buy Now', 'woocommerce');
}
/** default */
return __('Add to cart', 'woocommerce');
}
开发者ID:justingreerbbi,项目名称:user-waller-credit-system,代码行数:9,代码来源:filters.php
示例8: getTourDestination
protected function getTourDestination($post)
{
$toursRegions = array('N. America', 'Latin America', 'Europe', 'Asia', 'Africa', 'Oceania');
if (has_term($toursRegions, 'destinations')) {
$getTermsArgs = array('fields' => 'names');
$tourPostTerms = wp_get_post_terms(get_the_id(), 'destinations', $getTermsArgs);
$result = array_values(array_intersect($toursRegions, $tourPostTerms));
return $result[0];
}
}
开发者ID:UWAA,项目名称:uwaa-2014,代码行数:10,代码来源:ThumbnailBrowser.php
示例9: affwp_drpc_edd_disable_referrals_per_category
/**
* Plugin Name: AffiliateWP - Disable Referrals Per Category In Easy Digital Downloads
* Plugin URI: http://affiliatewp.com
* Description: Disable referrals on specific product categories in Easy Digital Downloads
* Author: Andrew Munro
* Author URI: http://affiliatewp.com
* Version: 1.0
*/
function affwp_drpc_edd_disable_referrals_per_category($referral_amount, $affiliate_id, $amount, $reference, $product_id)
{
// Array of categories to disable referrals for. Separate by a comma and use either the term name, term_id, or slug
$disabled_categories = array('category-one', 5);
// Disable referral if product exists in array of categories
if (has_term($disabled_categories, 'download_category', $product_id)) {
$referral_amount = 0.0;
}
return $referral_amount;
}
开发者ID:companyjuice,项目名称:affiliatewp-code-snippet-library,代码行数:18,代码来源:disable-referrals-per-category-edd.php
示例10: createPostVar
public function createPostVar()
{
$posts = get_posts($this->args);
foreach ($posts as $post) {
$post_content = (array) $post->post_content;
if (has_term('Site', 'notice_type', $post)) {
$this->content = array_merge((array) $this->content, (array) $post_content);
}
}
}
开发者ID:klhall1987,项目名称:custom-frontend-notices,代码行数:10,代码来源:cfn-settings.php
示例11: wpt_filter_a_term
function wpt_filter_a_term($continue, $args)
{
$id = $args['id'];
// 1,2,3 are term IDs that should not be Tweeted.
$terms = array(1, 2, 3);
if (has_term($terms, 'post_tags', $id)) {
return false;
}
return $continue;
}
开发者ID:joedolson,项目名称:plugin-extensions,代码行数:10,代码来源:custom-tag-filter.php
示例12: has_post_format
/**
* Check if a post has any of the given formats, or any format.
*
* @since 3.1.0
*
* @param string|array $format Optional. The format or formats to check.
* @param object|int|null $post Optional. The post to check. If not supplied, defaults to the current post if used in the loop.
* @return bool True if the post has any of the given formats (or any format, if no format specified), false otherwise.
*/
function has_post_format($format = array(), $post = null)
{
$prefixed = array();
if ($format) {
foreach ((array) $format as $single) {
$prefixed[] = 'post-format-' . sanitize_key($single);
}
}
return has_term($prefixed, 'post_format', $post);
}
开发者ID:AndreyLanko,项目名称:perevorot-prozorro-wp,代码行数:19,代码来源:post-formats.php
示例13: ubik_recordpress_meta
function ubik_recordpress_meta($meta)
{
global $post;
if (has_term('', 'artists')) {
$meta .= ubik_terms_popular_list($post->ID, 'artists', 'Artists: ', ', ', '. ');
}
if (has_term('', 'styles')) {
$meta .= ubik_terms_popular_list($post->ID, 'styles', 'Styles: ', ', ', '. ');
}
return $meta;
}
开发者ID:synapticism,项目名称:ubik-recordpress,代码行数:11,代码来源:ubik-recordpress-core.php
示例14: has_post_format
/**
* Check if a post has a particular format
*
* @since 3.1.0
*
* @uses has_term()
*
* @param string|array $format The format or formats to check.
* @param object|int $post The post to check. If not supplied, defaults to the current post if used in the loop.
* @return bool True if the post has the format, false otherwise.
*/
function has_post_format($format, $post = null)
{
if (!is_array($format)) {
$format = array($format);
}
$prefixed = array();
foreach ($format as $single) {
$prefixed[] = 'post-format-' . sanitize_key($single);
}
return has_term($prefixed, 'post_format', $post);
}
开发者ID:mostafiz93,项目名称:PrintfScanf,代码行数:22,代码来源:post-formats.php
示例15: reg_assembly_cat
function reg_assembly_cat()
{
$labels = array('name' => _x('Assembly Categories', 'assembly-category'), 'singular_name' => _x('Assembly Category', 'assembly-category'), 'search_items' => _x('Search Assembly Category', 'assembly-category'), 'popular_items' => _x('Popular Assembly Category', 'assembly-category'), 'all_items' => _x('All Assembly Category', 'assembly-category'), 'parent_item' => _x('Parent Assembly Category', 'assembly-category'), 'parent_item_colon' => _x('Parent Assembly Category:', 'assembly-category'), 'edit_item' => _x('Edit Assembly Category', 'assembly-category'), 'update_item' => _x('Update Assembly Category', 'assembly-category'), 'add_new_item' => _x('Add New Assembly Category', 'assembly-category'), 'new_item_name' => _x('New Assembly Category', 'assembly-category'), 'separate_items_with_commas' => _x('Separate Assembly Category with commas', 'assembly-category'), 'add_or_remove_items' => _x('Add or remove Assembly Category', 'assembly-category'), 'choose_from_most_used' => _x('Choose from the most used Assembly Category', 'assembly-category'), 'menu_name' => _x('Categories', 'assembly-category'));
$args = array('labels' => $labels, 'public' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_ui' => true, 'show_tagcloud' => true, 'show_admin_column' => true, 'sort' => true, 'hierarchical' => true, 'rewrite' => true, 'query_var' => true);
register_taxonomy('assembly-category', array('assembly'), $args);
if (!has_term('assembly', 'assembly-category')) {
wp_insert_term('Assembly', 'assembly-category', array('Assembly', 'assembly'));
}
if (!has_term('sub-assembly', 'assembly-category')) {
wp_insert_term('Sub iAssembly', 'assembly-category', array('Sub Assembly', 'sub-assembly'));
}
}
开发者ID:amgxyz,项目名称:wc-bom,代码行数:12,代码来源:cpt-assembly.php
示例16: forbid_credits_page
function forbid_credits_page()
{
global $post;
$terms = wp_get_post_terms($post->ID, 'product_cat');
$categories = array();
foreach ($terms as $term) {
$categories[] = $term->slug;
}
if (is_product_category('credit') || is_product() && has_term('credit', 'product_cat')) {
header('Location: ' . get_permalink(woocommerce_get_page_id('shop')) . '');
}
}
开发者ID:ekussberg,项目名称:simple-credits,代码行数:12,代码来源:configuration.php
示例17: x_integrity_entry_meta
function x_integrity_entry_meta()
{
$author = sprintf('<span><i class="x-icon-pencil"></i> %s</span>', get_the_author());
$date = sprintf('<span><time class="entry-date" datetime="%1$s"><i class="x-icon-calendar"></i> %2$s</time></span>', esc_attr(get_the_date('c')), esc_html(get_the_date()));
if (get_post_type() == 'x-portfolio') {
if (has_term('', 'portfolio-category', NULL)) {
$categories = get_the_terms(get_the_ID(), 'portfolio-category');
$separator = ', ';
$categories_output = '';
foreach ($categories as $category) {
$categories_output .= '<a href="' . get_term_link($category->slug, 'portfolio-category') . '" title="' . esc_attr(sprintf(__("View all posts in: “%s”", '__x__'), $category->name)) . '"><i class="x-icon-bookmark"></i> ' . $category->name . '</a>' . $separator;
}
$categories_list = sprintf('<span>%s</span>', trim($categories_output, $separator));
} else {
$categories_list = '';
}
} else {
$categories = get_the_category();
$separator = ', ';
$categories_output = '';
foreach ($categories as $category) {
$categories_output .= '<a href="' . get_category_link($category->term_id) . '" title="' . esc_attr(sprintf(__("View all posts in: “%s”", '__x__'), $category->name)) . '"><i class="x-icon-bookmark"></i> ' . $category->name . '</a>' . $separator;
}
$categories_list = sprintf('<span>%s</span>', trim($categories_output, $separator));
}
if (comments_open()) {
$title = get_the_title();
$link = get_comments_link();
$number = get_comments_number();
if ($number == 0) {
$comments = sprintf('<span><a href="%1$s" title="%2$s" class="meta-comments"><i class="x-icon-comments"></i> %3$s</a></span>', esc_url($link), esc_attr(sprintf(__('Leave a comment on: “%s”', '__x__'), $title)), __('Leave a Comment', '__x__'));
} else {
if ($number == 1) {
$comments = sprintf('<span><a href="%1$s" title="%2$s" class="meta-comments"><i class="x-icon-comments"></i> %3$s</a></span>', esc_url($link), esc_attr(sprintf(__('Leave a comment on: “%s”', '__x__'), $title)), $number . ' ' . __('Comment', '__x__'));
} else {
$comments = sprintf('<span><a href="%1$s" title="%2$s" class="meta-comments"><i class="x-icon-comments"></i> %3$s</a></span>', esc_url($link), esc_attr(sprintf(__('Leave a comment on: “%s”', '__x__'), $title)), $number . ' ' . __('Comments', '__x__'));
}
}
} else {
$comments = '';
}
$post_type = get_post_type();
$post_type_post = $post_type == 'post';
$post_type_portfolio = $post_type == 'x-portfolio';
$no_post_meta = get_theme_mod('x_blog_enable_post_meta') == 0;
$no_portfolio_meta = get_theme_mod('x_portfolio_enable_post_meta') == 0;
if ($post_type_post && $no_post_meta || $post_type_portfolio && $no_portfolio_meta) {
return;
} else {
printf('<p class="p-meta">%1$s%2$s%3$s%4$s</p>', $author, $date, $categories_list, $comments);
}
}
开发者ID:Cywaithaka,项目名称:WPAN,代码行数:52,代码来源:integrity.php
示例18: theburgh_specials_template
function theburgh_specials_template($template)
{
$new_template = '';
if (is_single()) {
global $post;
if (has_term('longform', 'category', $post)) {
$new_template = locate_template(array('single-special.php'));
}
}
if ('' != $new_template) {
return $new_template;
}
return $template;
}
开发者ID:The-Pitt-News,项目名称:TheBurgh,代码行数:14,代码来源:functions.php
示例19: wpfc_sermon_update
function wpfc_sermon_update()
{
$sermon_settings = get_option('wpfc_options');
$sermon_version = $sermon_settings['version'];
$args = array('post_type' => 'wpfc_sermon', 'posts_per_page' => '-0');
$wpfc_sermon_update_query = new WP_Query($args);
while ($wpfc_sermon_update_query->have_posts()) {
$wpfc_sermon_update_query->the_post();
global $post;
if (empty($sermon_version)) {
$service_type = get_post_meta($post->ID, 'service_type', 'true');
if (!has_term('wpfc_service_type')) {
wp_set_object_terms($post->ID, $service_type, 'wpfc_service_type');
}
$current = get_post_meta($post->ID, 'sermon_audio', 'true');
$currentsize = get_post_meta($post->ID, '_wpfc_sermon_size', 'true');
// only grab if different (getting data from dropbox can be a bit slow)
if (empty($currentsize)) {
// get file data
$size = wpfc_get_filesize($current);
$duration = wpfc_mp3_duration($current);
// store in hidden custom fields
update_post_meta($post->ID, '_wpfc_sermon_duration', $duration);
update_post_meta($post->ID, '_wpfc_sermon_size', $size);
}
//Alter the options array appropriately
$sermon_settings['version'] = wpfc_plugin_get_version();
//Update entire array
update_option('wpfc_options', $sermon_settings);
}
if ($sermon_version < '1.8') {
$current = get_post_meta($post->ID, 'sermon_audio', 'true');
$currentsize = get_post_meta($post->ID, '_wpfc_sermon_size', 'true');
// only grab if different (getting data from dropbox can be a bit slow)
if (empty($currentsize)) {
// get file data
$size = wpfc_get_filesize($current);
$duration = wpfc_mp3_duration($current);
// store in hidden custom fields
update_post_meta($post->ID, '_wpfc_sermon_duration', $duration);
update_post_meta($post->ID, '_wpfc_sermon_size', $size);
}
//Alter the options array appropriately
$sermon_settings['version'] = wpfc_plugin_get_version();
//Update entire array
update_option('wpfc_options', $sermon_settings);
}
}
wp_reset_query();
}
开发者ID:mlloewen,项目名称:wp-muirlake,代码行数:50,代码来源:upgrade.php
示例20: add_view_cover_to_action_box
function add_view_cover_to_action_box()
{
if (is_singular('cases') and has_term($this->case_category, 'functions')) {
$url = add_query_arg(array('view' => $this->url_key));
?>
<li>
<a href="<?php
echo $url;
?>
" target="_blank">Печать исходящего письма</a>
</li>
<?php
}
}
开发者ID:systemo-biz,项目名称:print_form_outgoing_mail_cp,代码行数:14,代码来源:_load.php
注:本文中的has_term函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论