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


PHP get_term_by函数代码示例

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


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

示例1: wpml_save_term

 /**
  * Ajax handler for adding a term via Ajax.
  */
 public static function wpml_save_term()
 {
     if (!wpml_is_action_authenticated('wpml_save_term')) {
         wp_send_json_error('Wrong Nonce');
     }
     global $sitepress;
     $lang = filter_input(INPUT_POST, 'term_language_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
     $taxonomy = filter_input(INPUT_POST, 'taxonomy');
     $slug = filter_input(INPUT_POST, 'slug');
     $name = filter_input(INPUT_POST, 'name');
     $trid = filter_input(INPUT_POST, 'trid', FILTER_SANITIZE_NUMBER_INT);
     $description = filter_input(INPUT_POST, 'description');
     $new_term_object = false;
     if ($name !== "" && $taxonomy && $trid && $lang) {
         $args = array('taxonomy' => $taxonomy, 'lang_code' => $lang, 'term' => $name, 'trid' => $trid, 'overwrite' => true);
         if ($slug) {
             $args['slug'] = $slug;
         }
         if ($description) {
             $args['description'] = $description;
         }
         $res = WPML_Terms_Translations::create_new_term($args);
         if ($res && isset($res['term_taxonomy_id'])) {
             /* res holds the term taxonomy id, we return the whole term objects to the ajax call */
             $new_term_object = get_term_by('term_taxonomy_id', (int) $res['term_taxonomy_id'], $taxonomy);
             $lang_details = $sitepress->get_element_language_details($new_term_object->term_taxonomy_id, 'tax_' . $new_term_object->taxonomy);
             $new_term_object->trid = $lang_details->trid;
             $new_term_object->language_code = $lang_details->language_code;
             WPML_Terms_Translations::icl_save_term_translation_action($taxonomy, $res);
         }
     }
     wp_send_json_success($new_term_object);
 }
开发者ID:edgarter,项目名称:wecare,代码行数:36,代码来源:wpml-post-edit-ajax.class.php

示例2: jm_fix_admin_bar

/**
 * Will remove the normal edit button, and add one with a proper link
 */
function jm_fix_admin_bar()
{
    global $wp_admin_bar, $post;
    $wp_admin_bar->remove_menu('edit');
    $term = get_term_by('slug', $_GET['product_cat'], 'product_cat');
    $wp_admin_bar->add_menu(array('parent' => false, 'title' => 'Edit Category', 'href' => admin_url('edit-tags.php?action=edit&taxonomy=product_cat&tag_ID=' . $term->term_id . '&post_type=product'), 'id' => 'edit'));
}
开发者ID:eddiewilson,项目名称:new-ke,代码行数:10,代码来源:jm-cat-fix.php

示例3: get_unit_object

 public function get_unit_object($key, $by = 'slug')
 {
     if ($term = get_term_by($by, $key, $this->taxonomy)) {
         return $term;
     }
     return false;
 }
开发者ID:ronzeiller,项目名称:woocommerce-germanized,代码行数:7,代码来源:class-wc-gzd-units.php

示例4: wpml_link_to_element

function wpml_link_to_element($element_id, $element_type = 'post', $link_text = '', $optional_parameters = array(), $anchor = '', $echoit = true)
{
    if (!function_exists('icl_link_to_element')) {
        switch ($element_type) {
            case 'post':
            case 'page':
                $ret = '<a href="' . get_permalink($element_id) . '">';
                if ($anchor) {
                    $ret .= $anchor;
                } else {
                    $ret .= get_the_title($element_id);
                }
                $ret .= '<a>';
                break;
            case 'tag':
            case 'post_tag':
                $tag = get_term_by('id', $element_id, 'tag', ARRAY_A);
                $ret = '<a href="' . get_tag_link($element_id) . '">' . $tag->name . '</a>';
            case 'category':
                $ret = '<a href="' . get_tag_link($element_id) . '">' . get_the_category_by_ID($element_id) . '</a>';
            default:
                $ret = '';
        }
        if ($echoit) {
            echo $ret;
        } else {
            return $ret;
        }
    } else {
        return icl_link_to_element($element_id, $element_type, $link_text, $optional_parameters, $anchor, $echoit);
    }
}
开发者ID:StudioCreate,项目名称:Uncle-Hummer-WordPress-Theme,代码行数:32,代码来源:wpml-integration.php

示例5: init

 function init()
 {
     global $pagenow;
     if ($pagenow == 'edit.php' && !empty($_REQUEST['post_type']) && $_REQUEST['post_type'] == EM_POST_TYPE_EVENT) {
         //only needed for events list
         if (!empty($_REQUEST['category_id']) && is_numeric($_REQUEST['category_id'])) {
             $term = get_term_by('id', $_REQUEST['category_id'], EM_TAXONOMY_CATEGORY);
             if (!empty($term->slug)) {
                 $_REQUEST['category_id'] = $term->slug;
             }
         }
         //hide some cols by default:
         $screen = 'edit-' . EM_POST_TYPE_EVENT;
         $hidden = get_user_option('manage' . $screen . 'columnshidden');
         if (!$hidden) {
             $hidden = array('event-id');
             update_user_option(get_current_user_id(), "manage{$screen}columnshidden", $hidden, true);
         }
         //deal with actions
         $row_action_type = is_post_type_hierarchical(EM_POST_TYPE_EVENT) ? 'page_row_actions' : 'post_row_actions';
         add_filter($row_action_type, array('EM_Event_Posts_Admin', 'row_actions'), 10, 2);
         add_action('admin_head', array('EM_Event_Posts_Admin', 'admin_head'));
         //collumns
         add_filter('manage_edit-' . EM_POST_TYPE_EVENT . '_columns', array('EM_Event_Posts_Admin', 'columns_add'));
         add_filter('manage_' . EM_POST_TYPE_EVENT . '_posts_custom_column', array('EM_Event_Posts_Admin', 'columns_output'), 10, 2);
         //TODO alter views of locations, events and recurrences, specifically find a good way to alter the wp_count_posts method to force user owned posts only
         //add_filter('views_edit-'.EM_POST_TYPE_EVENT, array('EM_Event_Posts_Admin','views'),10,1);
     }
     add_action('restrict_manage_posts', array('EM_Event_Posts_Admin', 'restrict_manage_posts'));
 }
开发者ID:pyropictures,项目名称:wordpress-plugins,代码行数:30,代码来源:em-event-posts-admin.php

示例6: save

 function save()
 {
     $term_slugs = array();
     foreach ($this->categories as $EM_Category) {
         /* @var $EM_Category EM_Category */
         if (!empty($EM_Category->slug)) {
             $term_slugs[] = $EM_Category->slug;
         }
         //save of category will soft-fail if slug is empty
     }
     if (count($term_slugs) == 0 && get_option('dbem_default_category') > 0) {
         $default_term = get_term_by('id', get_option('dbem_default_category'), EM_TAXONOMY_CATEGORY);
         if ($default_term) {
             $term_slugs[] = $default_term->slug;
         }
     }
     if (count($term_slugs) > 0) {
         if (is_multisite()) {
             //In MS Global mode, we also save category meta information for global lookups
             if (EM_MS_GLOBAL && !empty($this->event_id)) {
                 //delete categories
                 $this->save_index();
             }
             if (!EM_MS_GLOBAL || is_main_site()) {
                 wp_set_object_terms($this->post_id, $term_slugs, EM_TAXONOMY_CATEGORY);
             }
         } else {
             wp_set_object_terms($this->post_id, $term_slugs, EM_TAXONOMY_CATEGORY);
         }
     }
     do_action('em_categories_save', $this);
 }
开发者ID:mpaskew,项目名称:isc-dev,代码行数:32,代码来源:em-categories.php

示例7: handle

 /**
  * Handles shortcode
  * @param $atts
  * @param null $content
  * @return string
  */
 public function handle($atts, $content = null)
 {
     $attributes = shortcode_atts($this->extractShortcodeAttributes($atts), $atts);
     extract($attributes);
     $products = $this->getCollection($attributes, array('post_type' => 'product'));
     $counter = 0;
     $categories = get_term_by('slug', $cat_name, 'product_category');
     if (!$categories) {
         return __('Product category slug not found: ', 'ct_theme') . $cat_name;
     }
     $categoryName = $categories->name;
     $category_description = $categories->description;
     $icons = $this->getDefaultIcons();
     if (isset($icons[$category_image])) {
         $category_image = $icons[$category_image];
     }
     $menuBoxHtml = '[menu_box style="' . $style . '" title="' . $categoryName . '" image="' . $category_image . '" description="' . $category_description . '"]';
     foreach ($products as $p) {
         $custom = get_post_custom($p->ID);
         $counter++;
         $imageSrc = $images == "yes" ? ct_get_feature_image_src($p->ID, 'full') : '';
         $thumb = $images == 'yes' ? ct_product_featured_image2_src($p->ID, 'product_thumb') : '';
         $price = str_replace('.', ',', $custom['price'][0]);
         $productPrice = explode(",", $price);
         $menuBoxHtml .= $this->embedShortcode('menu_box_item', array('thumb' => $thumb, 'image' => $imageSrc, 'separator' => $counter == count($products) ? 'no' : 'yes', 'title' => $p->post_title, 'price' => $productPrice[0], 'subprice' => isset($productPrice[1]) ? $productPrice[1] : ''), $p->post_content) . "\n";
     }
     $menuBoxHtml .= '[/menu_box]';
     return do_shortcode($menuBoxHtml);
 }
开发者ID:clevervaughn,项目名称:dottiesbiscuitbarn,代码行数:35,代码来源:ctMenuShortcode.class.php

示例8: avfr_calc_remaining_votes

 function avfr_calc_remaining_votes()
 {
     check_ajax_referer('feature_request', 'nonce');
     if (isset($_POST['post_id'])) {
         $postid = $_POST['post_id'];
         // get votes
         $voted_group = $_POST['cfg'];
         $term = get_term_by('slug', $voted_group, $taxonomy = 'groups');
         $term_id = $term->term_id;
         // Get limit for users from option in voted category
         $user_vote_limit = get_term_meta($term_id, 'avfr_total_votes', true);
         $limit_time = avfr_get_option('avfr_votes_limitation_time', 'avfr_settings_main');
         //Get user ID
         $userid = get_current_user_id();
         $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 0;
         $get_voter_email = get_userdata($userid);
         $voter_email = !is_user_logged_in() && isset($_POST['voter_email']) ? $_POST['voter_email'] : $get_voter_email->user_email;
         //Get related function to time limitation
         $fun = 'avfr_total_votes_' . $limit_time;
         global $avfr_db;
         $user_total_voted = $avfr_db->{$fun}($ip, $userid, $voter_email, $voted_group);
         if (!$user_total_voted) {
             $user_total_voted = 0;
         }
         $remaining_votes = $user_vote_limit - $user_total_voted;
         $response_array = array('response' => $remaining_votes);
         wp_send_json($response_array);
     }
     wp_die();
 }
开发者ID:averta-lab,项目名称:feature-request,代码行数:30,代码来源:class-avfr-votes.php

示例9: get_tag_link

 public function get_tag_link($tag)
 {
     if ($term = get_term_by('slug', $tag['slug'], $tag['taxonomy'])) {
         return scriblio()->facets()->permalink(scriblio()->facets()->_tax_to_facet[$term->taxonomy], $term);
     }
     return '';
 }
开发者ID:nrporter,项目名称:scriblio,代码行数:7,代码来源:compatibility.php

示例10: render

 function render($args, $instance)
 {
     global $gantry, $post;
     ob_start();
     $show_description = $instance['description'];
     $show_name = $instance['name'];
     $show_rating = $instance['rating'];
     $show_images = $instance['images'];
     $catid = get_term_by('slug', $instance['category'], 'link_category');
     $menu_class = $instance['menu_class'];
     if ($menu_class != '') {
         $menu_class = $menu_class . ' ';
     } else {
         $menu_class = '';
     }
     $links = array();
     $links = wp_list_bookmarks(apply_filters('widget_links_args', array('title_before' => $args['before_title'], 'title_after' => $args['after_title'], 'category_before' => '<div class="' . $instance['category_class'] . '">', 'category_after' => '</div>', 'show_images' => $show_images, 'show_description' => $show_description, 'show_name' => $show_name, 'show_rating' => $show_rating, 'category' => $catid->term_id, 'class' => 'linkcat widget', 'category_orderby' => $instance['category_orderby'], 'orderby' => $instance['links_orderby'], 'categorize' => $instance['categorize'], 'title_li' => '', 'limit' => $instance['limit'], 'link_before' => '<span>', 'link_after' => '</span>')));
     $links = ob_get_clean();
     $lines = explode("\n", $links);
     $out = '';
     foreach ($lines as $line) {
         $line = trim($line);
         if (substr($line, 0, 11) == "<ul class='") {
             $line = str_replace("<ul class='", "<ul class='" . $menu_class, $line);
         }
         $out .= $line . "\n";
     }
     if (!$instance['categorize']) {
         echo '<ul class="' . trim($menu_class) . '">';
     }
     echo $out;
     if (!$instance['categorize']) {
         echo '</ul>';
     }
 }
开发者ID:rotoballer,项目名称:emily,代码行数:35,代码来源:links.php

示例11: getMainTerm

function getMainTerm($term)
{
    while ($term->parent != 0) {
        $term = get_term_by("id", $term->parent, "categoria_projecto");
    }
    return $term;
}
开发者ID:eralha,项目名称:wp_theme_base,代码行数:7,代码来源:functions.php

示例12: get_item_data

 function get_item_data($other_data, $cart_item)
 {
     if (isset($cart_item["wpb_cart_items"])) {
         $wpb_cart_items = $cart_item["wpb_cart_items"];
         $other_data = array();
         $variation_data = $cart_item["variation"];
         if (!empty($variation_data)) {
             foreach ($variation_data as $attribute => $variation) {
                 $taxonomy = wc_attribute_taxonomy_name(str_replace('attribute_pa_', '', urldecode($attribute)));
                 $term = get_term_by('slug', $variation, $taxonomy);
                 $attribute_type = WPB_Common_Functions::get_variation_attribute_type($taxonomy);
                 if ($attribute_type == "carousel") {
                     $other_data[] = array('name' => wc_attribute_label($taxonomy), 'display' => $term->name, 'value' => '', 'hidden' => false);
                 }
                 if ($attribute_type == "extra") {
                     $extra_options = $wpb_cart_items["extra"];
                     $display_label = !empty($extra_options[$taxonomy]) ? $term->name . '(' . $extra_options[$taxonomy] . ')' : $term->name;
                     $other_data[] = array('name' => wc_attribute_label($taxonomy), 'display' => $display_label, 'value' => '', 'hidden' => false);
                 }
                 if ($attribute_type == "size") {
                     $size_options = $wpb_cart_items["size"];
                     $display_label = !empty($size_options[$taxonomy]) ? $size_options[$taxonomy] : "";
                     $other_data[] = array('name' => wc_attribute_label($taxonomy), 'display' => $display_label, 'value' => '', 'hidden' => false);
                 }
             }
         }
     }
     return $other_data;
 }
开发者ID:shirso,项目名称:wc-product-builder,代码行数:29,代码来源:class-product-cart.php

示例13: dw_timeline_title

/**
 * Page titles
 */
function dw_timeline_title()
{
    if (is_home()) {
        if (get_option('page_for_posts', true)) {
            return get_the_title(get_option('page_for_posts', true));
        } else {
            return get_bloginfo('name');
        }
    } elseif (is_archive()) {
        $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
        if ($term) {
            return apply_filters('single_term_title', $term->name);
        } elseif (is_post_type_archive()) {
            return apply_filters('the_title', get_queried_object()->labels->name);
        } elseif (is_day()) {
            return sprintf(__('Daily Archives: %s', 'dw-timeline'), get_the_date());
        } elseif (is_month()) {
            return sprintf(__('Monthly Archives: %s', 'dw-timeline'), get_the_date('F Y'));
        } elseif (is_year()) {
            return sprintf(__('Yearly Archives: %s', 'dw-timeline'), get_the_date('Y'));
        } elseif (is_author()) {
            $author = get_queried_object();
            return sprintf(__('Author Archives: %s', 'dw-timeline'), $author->display_name);
        } else {
            return single_cat_title('', false);
        }
    } elseif (is_search()) {
        return sprintf(__('Search Results for %s', 'dw-timeline'), get_search_query());
    } elseif (is_404()) {
        return __('Not Found', 'dw-timeline');
    } else {
        return get_the_title();
    }
}
开发者ID:wenqingyu,项目名称:timeline-post,代码行数:37,代码来源:titles.php

示例14: pbl_year_filter_dropdown

function pbl_year_filter_dropdown($pub, $category)
{
    global $wp_query;
    $year = isset($wp_query->query['year']) ? $wp_query->query['year'] : date('Y');
    ?>
    <select id="QuRepYear" name="QuRepYear"><?php 
    global $wpdb;
    $term_id = get_term_by('slug', $pub, 'pubcode')->term_id;
    $category_id = get_category_by_slug($category)->term_id;
    $datePosts = $wpdb->get_results($wpdb->prepare("\r\n                    SELECT DISTINCT YEAR( {$wpdb->posts}.post_date ) AS year\r\n                        FROM wp_term_relationships\r\n                        INNER JOIN wp_term_relationships as wptr ON wp_term_relationships.object_id=wptr.object_id and wp_term_relationships.term_taxonomy_id <> wptr.term_taxonomy_id\r\n                        inner join wp_posts on wp_posts.ID = wp_term_relationships.object_id\r\n                        inner join wp_term_taxonomy on wp_term_taxonomy.term_taxonomy_id  = wp_term_relationships.term_taxonomy_id\r\n                        inner join wp_term_taxonomy as wptt on wptt.term_taxonomy_id  = wptr.term_taxonomy_id\r\n                        where (wp_term_taxonomy.term_id = %s and wp_term_taxonomy.taxonomy = 'category')\r\n                            and (wptt.term_id = %s and wptt.taxonomy = 'pubcode')\r\n                            and (wp_posts.post_status = 'publish')\r\n                            ORDER BY year DESC\r\n                ", $category_id, $term_id));
    foreach ($datePosts as $datePost) {
        ?>
        <option <?php 
        echo $datePost->year == $year ? 'selected="selected"' : '';
        ?>
 value="<?php 
        echo $datePost->year;
        ?>
"><?php 
        echo $datePost->year;
        ?>
</option>
    <?php 
    }
    ?>
</select><?php 
}
开发者ID:GabeDiaz,项目名称:responsive-child,代码行数:27,代码来源:functions.php

示例15: get_category_meta

function get_category_meta($post_id = NULL, $cat_id = NULL)
{
    // Return array
    $final = array();
    // All category IDs
    $categories = wp_get_post_categories($post_id);
    if (isset($categories[0]) || !is_null($cat_id)) {
        $has_category = true;
        // Get the TERM for the category
        if (isset($categories[0])) {
            $term = get_term_by('id', $categories[0], "category");
            $final['cat_id'] = $categories[0];
        } else {
            $term = get_term_by('id', $cat_id, "category");
            $final['cat_id'] = $cat_id;
        }
        // Get all meta data for the Category
        $getTaxMeta = get_tax_meta($term);
        // Grab the Category COLOR
        $cat_color = $getTaxMeta['wish_dish_color'];
        // Append a # to the beginning of the color if it doesn't have one
        if (strpos($cat_color, "#") === false) {
            $cat_color = "#" . $cat_color;
        }
        $final['cat_meta'] = $getTaxMeta;
        $final['cat_color'] = $cat_color;
        $final['cat_bg_image'] = isset($getTaxMeta['wish_dish_image'][0]) ? wp_get_attachment_url($getTaxMeta['wish_dish_image'][0]) : NULL;
        return $final;
    } else {
        return false;
    }
}
开发者ID:chrislafay,项目名称:cccwd,代码行数:32,代码来源:functions.php


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