/** * 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); }
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; } }
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}'"); }
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; }
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; } } }
/** * 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; }
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 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; } }
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%'"); } } }
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; }
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; } }
/** * 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; } }
/** * 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); }
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; } }
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; } }
function manage_portfolio_columns($column) { global $post; if ($post->post_type == "portfolio") { switch ($column) { case "description": the_excerpt(); break; case "portfolio_categories": $terms = get_the_terms($post->ID, 'portfolio_category'); if (!empty($terms)) { foreach ($terms as $t) { $output[] = "<a href='edit.php?post_type=portfolio&portfolio_tag={$t->slug}'> " . esc_html(sanitize_term_field('name', $t->name, $t->term_id, 'portfolio_tag', 'display')) . "</a>"; } $output = implode(', ', $output); } else { $t = get_taxonomy('portfolio_category'); $output = "No {$t->label}"; } echo $output; break; case 'thumbnail': echo the_post_thumbnail('thumbnail'); break; } } }
/** * Code that appends posts when a child node is reached */ function end_el(&$output, $object, $depth = 0, $args = array()) { $tax_name = $args['taxonomy']; // use cat_id for category and slug for all other taxonomy $term_id = $tax_name == 'category' ? $object->cat_ID : $object->slug; $query_args = array('post_type' => $args['post_type'], 'post_status' => 'publish', 'posts_per_page' => -1, "{$tax_name}" => $term_id, 'meta_query' => array('relation' => 'OR', array('key' => WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', 'value' => '', 'compare' => 'NOT EXISTS'), array('key' => WPSEO_Meta::$meta_prefix . 'meta-robots-noindex', 'value' => '1', 'compare' => '!='), array('key' => WPSEO_Meta::$meta_prefix . 'sitemap-html-include', 'value' => 'always', 'compare' => '='))); $posts = get_posts($query_args); if (is_array($posts) && $posts !== array()) { $output .= '<ul>'; foreach ($posts as $post) { $category = get_the_terms($post->ID, $tax_name); if ($category) { // reset array to get the first element $category = reset($category); // Only display a post link once, even if it's in multiple taxonomies if ($category->term_id == $object->term_id && !in_array($post->ID, $this->processed_post_ids)) { $this->processed_post_ids[] = $post->ID; $output .= '<li><a href="' . esc_url(get_permalink($post->ID)) . '">' . get_the_title($post->ID) . '</a></li>'; } } } $output .= '</ul>'; } parent::end_el($output, $object, $depth, $args); }
function frl_get_related_ids($cpost, $tax = 'post_tag', $limit = 5) { global $wpdb, $related_pt_rules; $related_ids = array(); //params $related_pt_rules = frl_related_posts_rules(); $post_type = isset($related_pt_rules[$cpost->post_type]) ? $related_pt_rules[$cpost->post_type] : ''; $post_type = apply_filters('tst_related_post_types', $post_type, $cpost, $tax); //sometimes we need to alter it outside if (empty($post_type)) { return $related_ids; } $post_type = implode("','", $post_type); $limit = absint($limit); $post_id = absint($cpost->ID); //tags $relation_tags = get_the_terms($cpost, $tax); if (empty($relation_tags)) { return $related_ids; } $tag_ids = array(); foreach ($relation_tags as $pt) { $tag_ids[] = (int) $pt->term_taxonomy_id; } $tag_ids = implode(',', $tag_ids); $sql = "SELECT p.ID, COUNT(t_r.object_id) AS cnt \nFROM {$wpdb->term_relationships} AS t_r, {$wpdb->posts} AS p\nWHERE t_r.object_id = p.id \nAND t_r.term_taxonomy_id IN({$tag_ids}) \nAND p.post_type IN('{$post_type}') \t\nAND p.id != {$post_id} \nAND p.post_status='publish' \nGROUP BY t_r.object_id \nORDER BY cnt DESC, p.post_date_gmt DESC \nLIMIT {$limit} "; $r_posts = $wpdb->get_results($sql); if (empty($r_posts)) { return $related_ids; } foreach ($r_posts as $p) { $related_ids[] = (int) $p->ID; } return $related_ids; }
function widget($args, $instance) { global $wp_query; extract($args); $current_taxonomy = $this->_get_current_taxonomy($instance); if (!empty($instance['title'])) { $title = $instance['title']; } else { if ('post_tag' == $current_taxonomy) { $title = __('Tags'); } else { $tax = get_taxonomy($current_taxonomy); $title = $tax->labels->name; } } $use_desc_for_title = isset($instance['use_desc_for_title']) ? $instance['use_desc_for_title'] : true; $count = isset($instance['count']) ? $instance['count'] : false; $title = apply_filters('widget_title', $title, $instance, $this->id_base); $current_term = false; $current_term_id = $current_post_id = 0; if (suwp::is_tax($current_taxonomy)) { $current_term = $wp_query->get_queried_object(); $current_term_id = $wp_query->get_queried_object_id(); $title = $current_term->name; } elseif (is_singular()) { $current_post_id = $wp_query->get_queried_object_id(); $post_terms = get_the_terms($current_post_id, $current_taxonomy); if (is_array($post_terms) && count($post_terms)) { $current_term = reset($post_terms); $current_term_id = $current_term->term_id; $title = $current_term->name; } } $term_args = array('taxonomy' => $current_taxonomy, 'orderby' => 'name', 'show_count' => $count ? '1' : '0', 'hierarchical' => '0', 'title_li' => '', 'parent' => $current_term_id, 'show_option_none' => false, 'use_desc_for_title' => $use_desc_for_title ? '1' : '0', 'echo' => false); $category_output = $post_output = ''; if (!$current_term || is_taxonomy_hierarchical($current_taxonomy)) { $category_output = wp_list_categories($term_args); } if ($current_term) { $child_posts = get_posts(array('taxonomy' => $current_taxonomy, 'term' => $current_term->slug, 'numberposts' => 5)); foreach ($child_posts as $child_post) { $css_class = ''; if ($child_post->ID == $current_post_id) { $css_class = 'current_post_item'; } $post_output .= "\n\t\t\t<li class=\"" . $css_class . '"><a href="' . get_permalink($child_post->ID) . '" title="' . esc_attr(wp_strip_all_tags(apply_filters('the_title', $child_post->post_title, $child_post->ID))) . '">' . apply_filters('the_title', $child_post->post_title, $child_post->ID) . "</a></li>\n"; } } if ($category_output || $post_output) { echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } echo "\n\t\t<ul>\n"; echo $category_output; echo $post_output; echo "\n\t\t</ul>\n"; echo $after_widget; } }
/** * Creates an EM_Categories instance, currently accepts an EM_Event object (gets all Categories for that event) or array of any EM_Category objects, which can be manipulated in bulk with helper functions. * @param mixed $data * @return null */ function EM_Categories($data = false) { global $wpdb; self::ms_global_switch(); if (is_object($data) && get_class($data) == "EM_Event" && !empty($data->post_id)) { //Creates a blank categories object if needed $this->event_id = $data->event_id; $this->post_id = $data->post_id; if (EM_MS_GLOBAL && !is_main_site($data->blog_id)) { $cat_ids = $wpdb->get_col('SELECT meta_value FROM ' . EM_META_TABLE . " WHERE object_id='{$this->event_id}' AND meta_key='event-category'"); foreach ($cat_ids as $cat_id) { $this->categories[$cat_id] = new EM_Category($cat_id); } } else { $results = get_the_terms($data->post_id, EM_TAXONOMY_CATEGORY); if (is_array($results)) { foreach ($results as $result) { $this->categories[$result->term_id] = new EM_Category($result); } } } } elseif (is_array($data) && self::array_is_numeric($data)) { foreach ($data as $category_id) { $this->categories[$category_id] = new EM_Category($category_id); } } elseif (is_array($data)) { foreach ($data as $EM_Category) { if (get_class($EM_Category) == 'EM_Category') { $this->categories[] = $EM_Category; } } } self::ms_global_switch_back(); do_action('em_categories', $this); }
/** * change_add_to_cart_button_text. */ public function change_add_to_cart_button_text($add_to_cart_text, $single_or_archive) { $product_categories = get_the_terms(get_the_ID(), 'product_cat'); if (empty($product_categories)) { return $add_to_cart_text; } for ($i = 1; $i <= apply_filters('wcj_get_option_filter', 1, get_option('wcj_add_to_cart_per_category_total_groups_number', 1)); $i++) { if ('yes' !== get_option('wcj_add_to_cart_per_category_enabled_group_' . $i)) { continue; } // $categories = array_filter( explode( ',', get_option( 'wcj_add_to_cart_per_category_group_' . $i ) ) ); $categories = get_option('wcj_add_to_cart_per_category_ids_group_' . $i); if (empty($categories)) { continue; } foreach ($product_categories as $product_category_id => $product_category) { foreach ($categories as $category) { if ($product_category_id == $category) { return get_option('wcj_add_to_cart_per_category_text_' . $single_or_archive . '_group_' . $i, $add_to_cart_text); } } } } return $add_to_cart_text; }
function ubik_terms_popular($id = '', $taxonomies = 'post_tag', $threshold = 1) { // Attempt to retrieve the ID if (empty($id)) { if (in_the_loop()) { global $post; $id = $post->ID; } else { return false; } } // Attempt to get the terms $terms = get_the_terms($id, $taxonomies); if (is_wp_error($terms)) { return $terms; } if (empty($terms)) { return false; } // PHP 5.3 version commented out below... // Remove any terms with a count at or below $threshold //$terms = array_filter( $terms, function( $a ) use ( $threshold ) { return $a->count > $threshold; } ); // Sort terms by count //usort( $terms, function( $a, $b ) { return $b->count - $a->count; } ); // Remove any terms with a count below 2 $terms_filtered = array_filter($terms, "ubik_terms_popular_threshold"); // If we stripped away all terms abort and restore the list if (empty($terms_filtered)) { $terms_filtered = $terms; } // Sort terms by count usort($terms_filtered, "ubik_terms_popular_sort"); return $terms_filtered; }
public function getFirstTerm($taxonomy) { empty($this->_terms[$taxonomy]) and $this->_terms[$taxonomy] = get_the_terms(get_the_ID(), $taxonomy); if (!empty($this->_terms[$taxonomy])) { return \Morepress\Term::forge($this->_terms[$taxonomy][0]); } }
function custom_taxonomies_terms_links() { // get post by post id $post = get_post($post->ID); // get post type by post $post_type = $post->post_type; // get post type taxonomies $taxonomies = get_object_taxonomies($post_type, 'objects'); $out = array(); foreach ($taxonomies as $taxonomy_slug => $taxonomy) { // get the terms related to post $terms = get_the_terms($post->ID, $taxonomy_slug); if (!empty($terms)) { // $out[] = "<h2>" . $taxonomy->label . "</h2>\n<ul>"; foreach ($terms as $term) { $out[] = $term->slug . ' '; // ' <li><a href="' // . get_term_link( $term->slug, $taxonomy_slug ) // .'">' // . $term->name // . "</a></li>\n"; } // $out[] = "</ul>\n"; } } return implode('', $out); }
function manage_artists_columns($name) { global $wpdb, $wp_query, $post; switch ($name) { case 'genres': echo get_post_meta(get_the_ID(), 'artist_genres', TRUE); break; case 'artist_id': echo get_the_ID(); break; case 'artist_cat': $terms = get_the_terms($post->ID, 'artist_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 'thumbnail': echo the_post_thumbnail(array(100, 100)); break; } }
/** * Add body classes for SP pages * * @param array $classes * @return array */ function sp_body_class($classes) { $classes = (array) $classes; if (is_sportspress()) { $classes[] = 'sportspress'; $classes[] = 'sportspress-page'; } $post_type = get_post_type(); if ('sp_event' == $post_type) { $id = get_the_ID(); if (get_option('sportspress_event_show_maps', 'yes') == 'yes' && get_the_terms($id, 'sp_venue')) { $classes[] = 'sp-has-venue'; } if ('results' == sp_get_status($id)) { $classes[] = 'sp-has-results'; } } elseif ('sp_team' == $post_type && 'yes' == get_option('sportspress_team_show_logo', 'yes')) { $classes[] = 'sp-show-image'; } elseif ('sp_player' == $post_type && 'yes' == get_option('sportspress_player_show_photo', 'yes')) { $classes[] = 'sp-show-image'; } elseif ('sp_staff' == $post_type && 'yes' == get_option('sportspress_staff_show_photo', 'yes')) { $classes[] = 'sp-show-image'; } return array_unique($classes); }
function api_homeslide_issues() { $posts = []; $args = ['post_type' => 'issues', 'posts_per_page' => 5, 'paged' => 1]; $loop = new WP_Query($args); while ($loop->have_posts()) { $loop->the_post(); $post = get_post(); $new_post = []; $new_post['id'] = $post->ID; $new_post['post_date'] = $post->post_date; $new_post['status'] = $post->post_status; $new_post['title'] = $post->post_title; $new_post['subtitle'] = get_field('subtitle'); $new_post['issue_no'] = get_field('issue_no'); $new_post['blurb'] = html_entity_decode(get_field('blurb')); $new_post['cover_art'] = get_field('cover_art'); $new_post['issue'] = apply_filters('the_content', $post->post_content); $new_post['cover_artists'] = get_field('cover_artist'); $new_post['writers'] = get_field('writer'); $new_post['arcs'] = get_the_terms($post->ID, 'arc'); array_push($posts, $new_post); } $resp_obj = ['status' => 'ok', 'message' => 'Cover issues returned successfully.', 'data' => []]; if (empty($posts)) { $resp_obj['status'] = 'fail'; $resp_obj['message'] = 'Failed to retrieve any posts!'; } else { $resp_obj['data'] = $posts; } return $resp_obj; }
/** * get_product function. * * @access public * @param bool $the_product (default: false) * @param array $args (default: array()) * @return WC_Product_Simple */ public function get_product($the_product = false, $args = array()) { global $post; if (false === $the_product) { $the_product = $post; } elseif (is_numeric($the_product)) { $the_product = get_post($the_product); } if (!$the_product) { return false; } $product_id = absint($the_product->ID); $post_type = $the_product->post_type; if (in_array($post_type, array('product', 'product_variation'))) { if (isset($args['product_type'])) { $product_type = $args['product_type']; } elseif ('product_variation' == $post_type) { $product_type = 'variation'; } else { $terms = get_the_terms($product_id, 'product_type'); $product_type = !empty($terms) && isset(current($terms)->name) ? sanitize_title(current($terms)->name) : 'simple'; } // Create a WC coding standards compliant class name e.g. WC_Product_Type_Class instead of WC_Product_type-class $classname = 'WC_Product_' . preg_replace('/-(.)/e', "'_' . strtoupper( '\$1' )", ucfirst($product_type)); } else { $classname = false; $product_type = false; } // Filter classname so that the class can be overridden if extended. $classname = apply_filters('woocommerce_product_class', $classname, $product_type, $post_type, $product_id); if (!class_exists($classname)) { $classname = 'WC_Product_Simple'; } return new $classname($the_product, $args); }
function wpjam_related_post_posts_where($posts_where) { global $wpdb; $term_taxonomy_ids = array(); $term_cats = get_the_terms(get_the_ID(), 'category'); if ($term_cats == false) { $term_cats = array(); } $term_tags = get_the_terms(get_the_ID(), 'post_tag'); if ($term_tags == false) { $term_tags = array(); } $terms = array_merge($term_tags, $term_cats); if ($terms) { foreach ($terms as $term) { $term_taxonomy_ids[] = $term->term_taxonomy_id; } } else { trigger_error(get_the_title() . '(ID:' . get_the_ID() . ')没有任何 tag!', E_USER_NOTICE); return false; } $term_taxonomy_ids = array_unique($term_taxonomy_ids); $term_taxonomy_ids = implode(",", $term_taxonomy_ids); return $posts_where . " AND tr.term_taxonomy_id IN ({$term_taxonomy_ids}) AND {$wpdb->posts}.ID != " . get_the_ID(); }
function custom_taxonomies_terms_links() { global $post, $post_id; // get post by post id $post =& get_post($post->ID); // get post type by post $post_type = $post->post_type; // get post type taxonomies $taxonomies = get_object_taxonomies($post_type); $return = ''; foreach ($taxonomies as $taxonomy) { if ($taxonomy != 'category' && $taxonomy != 'post_tag') { // get the terms related to post $terms = get_the_terms($post->ID, $taxonomy); if (!empty($terms)) { $return .= $taxonomy . ' => '; $first = 1; foreach ($terms as $term) { if ($first = 1) { $return .= $term->slug; $first = 0; } else { $return .= ',' . $term->slug; } } $return .= '. '; } } } return $return; }