/** * 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); }
/** * 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')); }
public function get_unit_object($key, $by = 'slug') { if ($term = get_term_by($by, $key, $this->taxonomy)) { return $term; } return false; }
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); } }
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')); }
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); }
/** * 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); }
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(); }
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 ''; }
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>'; } }
function getMainTerm($term) { while ($term->parent != 0) { $term = get_term_by("id", $term->parent, "categoria_projecto"); } return $term; }
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; }
/** * 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(); } }
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 }
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; } }
function wpjam_related_posts_shortcode($atts, $content = '') { extract(shortcode_atts(array('tag' => '0'), $atts)); if ($tag) { if (isset($_GET['update'])) { wp_cache_delete(md5($tag), 'related_posts_query'); } $related_posts_query = wp_cache_get(md5($tag), 'related_posts_query'); if ($related_posts_query === false) { $tags = explode(",", $tag); $tag_id_array = array(); foreach ($tags as $a_tag) { $tag_object = get_term_by('name', trim($a_tag), 'post_tag'); $tag_id_array[] = $tag_object->term_id; } $post_types = apply_filters('wpjam_related_posts_post_types', array(get_post_type())); if (count($tag_id_array) > 1) { $related_posts_query = new WP_Query(array('post_type' => get_post_type(), 'post_status' => 'publish', 'tag__and' => $tag_id_array, 'post__not_in' => array(get_the_ID()))); } else { $related_posts_query = new WP_Query(array('post_type' => get_post_type(), 'post_status' => 'publish', 'tag_id' => $tag_id_array[0], 'post__not_in' => array(get_the_ID()))); } wp_cache_set(md5($tag), $related_posts_query, 'related_posts_query', 3600); } return wpjam_get_post_list($related_posts_query, array('thumb' => false, 'class' => 'related_posts')); } }
function setUp() { global $wp_rewrite; parent::setUp(); set_current_screen('front'); $GLOBALS['wp_the_query'] = new WP_Query(); $GLOBALS['wp_query'] = $GLOBALS['wp_the_query']; $wp_rewrite->init(); $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/'); create_initial_taxonomies(); register_taxonomy('testtax', 'post', array('public' => true)); $wp_rewrite->flush_rules(); $this->tag_id = $this->factory->tag->create(array('slug' => 'tag-slug')); $this->cat_id = $this->factory->category->create(array('slug' => 'cat-slug')); $this->tax_id = $this->factory->term->create(array('taxonomy' => 'testtax', 'slug' => 'tax-slug')); $this->tax_id2 = $this->factory->term->create(array('taxonomy' => 'testtax', 'slug' => 'tax-slug2')); $this->post_id = $this->factory->post->create(); wp_set_object_terms($this->post_id, $this->cat_id, 'category'); wp_set_object_terms($this->post_id, array($this->tax_id, $this->tax_id2), 'testtax'); $this->cat = get_term($this->cat_id, 'category'); _make_cat_compat($this->cat); $this->tag = get_term($this->tag_id, 'post_tag'); $this->uncat = get_term_by('slug', 'uncategorized', 'category'); _make_cat_compat($this->uncat); add_action('pre_get_posts', array($this, 'pre_get_posts_tax_category_tax_query')); }
function colabsthemes_script_and_style() { // Styles wp_enqueue_style('framework', get_template_directory_uri() . '/includes/css/framework.css'); wp_enqueue_style('style', get_stylesheet_directory_uri() . '/style.css', array('framework')); wp_enqueue_style('mmenu-style', get_stylesheet_directory_uri() . '/includes/css/jquery.mmenu.css'); // Scripts wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-slider'); // Only load fancybox on single property if ('property' == get_post_type()) { wp_enqueue_script('fancybox', get_template_directory_uri() . '/includes/js/fancybox/jquery.fancybox-1.3.4.pack.js', array('jquery'), '', true); wp_enqueue_style('fancybox', get_template_directory_uri() . '/includes/js/fancybox/jquery.fancybox-1.3.4.css'); } wp_enqueue_script('plugins', trailingslashit(get_template_directory_uri()) . 'includes/js/plugins.js', array('jquery'), '', true); wp_enqueue_script('scripts', trailingslashit(get_template_directory_uri()) . 'includes/js/scripts.js', array('jquery'), '', true); /* Script for threaded comments. */ if (is_singular() && get_option('thread_comments')) { wp_enqueue_script('comment-reply'); } wp_localize_script('scripts', 'translationstring', array('nomorepost' => __('No More Post', 'colabsthemes'))); // Translatable string for form builder $rent_term_obj = get_term_by('slug', 'rent', COLABS_TAX_STATUS); $term_id = isset($rent_term_obj->term_id) ? $rent_term_obj->term_id : ''; $formbuilder_string = array('media_upload' => array('title' => __('Upload', 'colabsthemes'), 'button_text' => __('Use this file', 'colabsthemes')), 'gallery_upload' => array('title' => __('Add Images to Gallery', 'colabsthemes'), 'button_text' => __('Add to gallery', 'colabsthemes')), 'file_upload' => array('title' => __('Choose a File', 'colabsthemes'), 'button_text' => __('Insert file URL', 'colabsthemes')), 'validator' => array('required' => __('This field is required', 'colabsthemes'), 'terms' => __('You need to aggree with our terms', 'colabsthemes')), 'delete_confirm' => __("Are your sure you want to delete this? It can't be undone.", 'colabsthemes'), 'cancel_order_confirm' => __("Are you sure you want to cancel this order? It can't be undone.", 'colabsthemes'), 'rent_term_id' => $term_id); wp_localize_script('scripts', 'formbuilder_string', $formbuilder_string); if (is_page_template('template-profile.php')) { wp_enqueue_script('password-strength-meter'); wp_enqueue_script('zxcvbn-async'); wp_enqueue_script('custom-strengthmeter', trailingslashit(get_template_directory_uri()) . 'includes/js/custom-strengthmeter.js'); } }
function ubik_terms_tag_shortcode($atts, $content = '') { // Setup variables $args = shortcode_atts(array('slug' => ''), $atts); $slug = (string) $args['slug']; $taxonomy = 'post_tag'; $term = $link = ''; // If the slug is not empty try to fetch the term and generate a link if (!empty($slug)) { $term = get_term_by('slug', $slug, $taxonomy); } elseif (empty($slug) && !empty($content)) { $term = get_term_by('slug', strtolower($content), $taxonomy); } // Try to generate a link if (!empty($term)) { $link = get_term_link($term); } // Assemble the HTML if (!empty($link)) { if (!empty($content)) { $content = '<a href="' . $link . '" rel="tag">' . $content . '</a>'; } elseif (empty($content)) { $content = '<a href="' . $link . '" rel="tag">' . $term->name . '</a>'; // Allows for [tag slug=example/] to fill content } } return apply_filters('ubik_terms_tag_shortcode', $content); }
/** * Set installed option and default settings / terms * * @since 1.0 */ private function maybe_install() { global $woocommerce; $installed_version = get_option('wc_pre_orders_version'); // install if (!$installed_version) { // add 'pre-order' shop order status term $woocommerce->init_taxonomy(); if (!get_term_by('slug', 'pre-ordered', 'shop_order_status')) { wp_insert_term('pre-ordered', 'shop_order_status'); } // install default settings foreach ($this->get_settings() as $setting) { if (isset($setting['default'])) { update_option($setting['id'], $setting['default']); } } } // upgrade - installed version lower than plugin version? if (-1 === version_compare($installed_version, WC_Pre_Orders::VERSION)) { $this->upgrade($installed_version); // new version number update_option('wc_pre_orders_version', WC_Pre_Orders::VERSION); } }
function sync_variation_swatches_and_photos($original_product_id, $trnsl_product_id, $data = false) { global $sitepress, $wpdb; $atts = maybe_unserialize(get_post_meta($original_product_id, '_swatch_type_options', true)); $lang = $sitepress->get_language_for_element($trnsl_product_id, 'post_product'); $tr_atts = $atts; foreach ($atts as $att_name => $att_opts) { foreach ($att_opts['attributes'] as $slug => $options) { $o_term = get_term_by('slug', $slug, $att_name); $tr_term_id = icl_object_id($o_term->term_id, $att_name, false, $lang); if (!is_null($tr_term_id)) { $tr_term = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->terms} t JOIN {$wpdb->term_taxonomy} x ON x.term_id = t.term_id WHERE t.term_id = %d AND x.taxonomy = %s", $tr_term_id, $att_name)); $tr_slug = $tr_term->slug; if ($tr_slug != '') { $tr_atts[$att_name]['attributes'][$tr_term->slug] = $atts[$att_name]['attributes'][$slug]; if (isset($options['image'])) { $o_img_id = $options['image']; $tr_img_id = icl_object_id($o_img_id, 'image', false, $lang); } unset($tr_atts[$att_name]['attributes'][$slug]); } } } } update_post_meta($trnsl_product_id, '_swatch_type_options', $tr_atts); // Meta gets overwritten }
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; }
function road_popular_categories_shortcode($atts) { $atts = shortcode_atts(array('category' => '', 'image' => ''), $atts, 'popular_categories'); $html = ''; $html .= '<div class="category-wrapper">'; $pcategory = get_term_by('slug', $atts['category'], 'product_cat', 'ARRAY_A'); if ($pcategory) { $html .= '<div class="category-list">'; $html .= '<h3><a href="' . get_term_link($pcategory['slug'], 'product_cat') . '">' . $pcategory['name'] . '</a></h3>'; $html .= '<ul>'; $args2 = array('taxonomy' => 'product_cat', 'child_of' => 0, 'parent' => $pcategory['term_id'], 'orderby' => 'name', 'show_count' => 0, 'pad_counts' => 0, 'hierarchical' => 0, 'title_li' => '', 'hide_empty' => 0); $sub_cats = get_categories($args2); if ($sub_cats) { foreach ($sub_cats as $sub_category) { $html .= '<li><a href="' . get_term_link($sub_category->slug, 'product_cat') . '">' . $sub_category->name . '</a></li>'; } } $html .= '</ul>'; $html .= '</div>'; if ($atts['image'] != '') { $html .= '<div class="cat-img">'; $html .= '<a href="' . get_term_link($pcategory['slug'], 'product_cat') . '"><img class="category-image" src="' . esc_attr($atts['image']) . '" alt="" /></a>'; $html .= '</div>'; } } $html .= '</div>'; return $html; }
/** * Gets data from POST (default), supplied array, or from the database if an ID is supplied * @param $tag_data * @return null */ function EM_Tag($tag_data = false) { global $wpdb; //Initialize $tag = array(); if (!empty($tag_data)) { //Load tag data if (is_object($tag_data) && !empty($tag_data->taxonomy) && $tag_data->taxonomy == EM_TAXONOMY_TAG) { $tag = $tag_data; } elseif (!is_numeric($tag_data)) { $tag = get_term_by('name', $tag_data, EM_TAXONOMY_TAG); if (empty($tag)) { $tag = get_term_by('slug', $tag_data, EM_TAXONOMY_TAG); } } else { $tag = get_term_by('id', $tag_data, EM_TAXONOMY_TAG); } } if (!empty($tag)) { foreach ($tag as $key => $value) { $this->{$key} = $value; } $this->id = $this->term_id; //backward compatability } do_action('em_tag', $this, $tag_data); }
public static function add_source_default() { global $wpdb; if (empty(self::$source_list)) { return false; } foreach (self::$source_list as $source) { if (isset($source['name'])) { $term = get_term_by('name', $source['name'], 'dln_source_cat'); if (empty($term)) { $term = wp_insert_term(esc_sql($source['name']), 'dln_source_cat'); } if (!empty($term->term_id) && isset($source['link'])) { $links = $source['link']; if (is_array($links)) { foreach ($links as $i => $link) { $sql = $wpdb->prepare("SELECT id from {$wpdb->dln_news_source} WHERE link = %s", esc_sql($link)); $exists = $wpdb->get_row($sql); if (empty($exists)) { $result = $wpdb->insert($wpdb->dln_news_source, array('term_id' => esc_sql($term->term_id), 'link' => esc_sql($link), 'source_type' => esc_sql($source['source_type']), 'tags' => esc_sql($source['tags']), 'type' => esc_sql($source['type']))); } if (is_wp_error($result)) { var_dump($result); } } } } } } exit; }
/** * Page titles */ function pinnacle_title() { if (is_home()) { if (get_option('page_for_posts', true)) { return get_the_title(get_option('page_for_posts', true)); } else { return __('Latest Posts', 'pinnacle'); } } elseif (is_archive()) { $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); if ($term) { return $term->name; } elseif (is_post_type_archive()) { return get_queried_object()->labels->name; } elseif (is_day()) { return sprintf(__('Daily Archives: %s', 'pinnacle'), get_the_date()); } elseif (is_month()) { return sprintf(__('Monthly Archives: %s', 'pinnacle'), get_the_date('F Y')); } elseif (is_year()) { return sprintf(__('Yearly Archives: %s', 'pinnacle'), get_the_date('Y')); } elseif (is_author()) { return sprintf(__('Author Archives: %s', 'pinnacle'), get_the_author()); } else { return single_cat_title("", false); } } elseif (is_search()) { return sprintf(__('Search Results for %s', 'pinnacle'), get_search_query()); } elseif (is_404()) { return __('Not Found', 'pinnacle'); } else { return get_the_title(); } }
/** * Gets data from POST (default), supplied array, or from the database if an ID is supplied * @param $category_data * @return null */ function __construct($category_data = false) { global $wpdb; self::ms_global_switch(); //Initialize $category = array(); if (!empty($category_data)) { //Load category data if (is_object($category_data) && !empty($category_data->taxonomy) && $category_data->taxonomy == EM_TAXONOMY_CATEGORY) { $category = $category_data; } elseif (!is_numeric($category_data)) { $category = get_term_by('slug', $category_data, EM_TAXONOMY_CATEGORY); if (!$category) { $category = get_term_by('name', $category_data, EM_TAXONOMY_CATEGORY); } } else { $category = get_term_by('id', $category_data, EM_TAXONOMY_CATEGORY); } } if (is_object($category) || is_array($category)) { foreach ($category as $key => $value) { $this->{$key} = $value; } } $this->id = $this->term_id; //backward compatability self::ms_global_switch_back(); do_action('em_category', $this, $category_data); }
/** * Page titles */ function roots_title() { if (is_home()) { if (get_option('page_for_posts', true)) { return get_the_title(get_option('page_for_posts', true)); } else { return __('Most Recent Posts', 'roots'); } } 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(__('Old Posts, Organized by Day: %s', 'roots'), get_the_date()); } elseif (is_month()) { return sprintf(__('Old Posts, Organized by Month: %s', 'roots'), get_the_date('F Y')); } elseif (is_year()) { return sprintf(__('Old Posts, Organized by Year: %s', 'roots'), get_the_date('Y')); } elseif (is_author()) { $author = get_queried_object(); return sprintf(__('Old Posts, Organized by Author: %s', 'roots'), apply_filters('the_author', is_object($author) ? $author->display_name : null)); } else { return single_cat_title('', false); } } elseif (is_search()) { return sprintf(__('Search Results for %s', 'roots'), get_search_query()); } elseif (is_404()) { return __('Not Found', 'roots'); } else { return get_the_title(); } }
/** * Page titles */ function stachestack_title() { if (is_home()) { if (get_option('page_for_posts', true)) { $title = get_the_title(get_option('page_for_posts', true)); } else { $title = __('Latest Posts', 'stachestack'); } } elseif (is_archive()) { $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); if ($term) { $title = apply_filters('single_term_title', $term->name); } elseif (is_post_type_archive()) { $title = apply_filters('the_title', get_queried_object()->labels->name); } elseif (is_day()) { $title = sprintf(__('Daily Archives: %s', 'stachestack'), get_the_date()); } elseif (is_month()) { $title = sprintf(__('Monthly Archives: %s', 'stachestack'), get_the_date('F Y')); } elseif (is_year()) { $title = sprintf(__('Yearly Archives: %s', 'stachestack'), get_the_date('Y')); } elseif (is_author()) { $title = sprintf(__('Author Archives: %s', 'stachestack'), get_queried_object()->display_name); } else { $title = single_cat_title('', false); } } elseif (is_search()) { $title = sprintf(__('Search Results for %s', 'stachestack'), get_search_query()); } elseif (is_404()) { $title = __('Not Found', 'stachestack'); } else { $title = get_the_title(); } return apply_filters('stachestack_title', $title); }
function afia_title() { if (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', 'afia'), get_the_date()); } elseif (is_month()) { return sprintf(__('Monthly Archives: %s', 'afia'), get_the_date('F Y')); } elseif (is_year()) { return sprintf(__('Yearly Archives: %s', 'afia'), get_the_date('Y')); } elseif (is_author()) { $author = get_queried_object(); return sprintf(__('Author Archives: %s', 'afia'), $author->display_name); } else { return single_cat_title('', false); } } elseif (is_search()) { return sprintf(__('Search Results for %s', 'afia'), get_search_query()); } elseif (is_404()) { return __('Not Found', 'afia'); } else { $c = get_the_category(); $cat_name = $c[0]->name; $cat_id = get_cat_ID($cat_name); $cat_link = get_category_link($cat_id); $lk = '<span class="idle"><a href = "' . $cat_link . '" title = "' . __('Category ', 'afia') . '->' . $cat_name . '">' . $cat_name . '</a></span> | ' . get_the_title(); return $lk; } }