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


PHP has_term函数代码示例

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


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


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