function jellythemes_photos_list($atts, $content = null) { extract(shortcode_atts(array('limit' => 8), $atts)); $return = ' <nav class="primary"><ul> <li><a class="selected" href="#" data-filter="*"><span>' . __('All photos', 'jellythemes') . '</span></a></li>'; $types = get_terms('type', array('hide_empty' => 0)); if ($types && !is_wp_error($types)) { foreach ($types as $type) { $return .= '<li><a href="#" data-filter=".' . esc_js($type->slug) . '"><span>' . $type->name . '</span></a></li>'; } } $return .= '</ul></nav> <div class="portfolio">'; $photos = new WP_Query(array('post_type' => 'photo', 'posts_per_page' => esc_attr($limit))); while ($photos->have_posts()) { $photos->the_post(); $term_list = wp_get_post_terms(get_the_ID(), 'type', array("fields" => "names")); $images = rwmb_meta('_jellythemes_project_images', 'type=plupload_image', get_the_ID()); foreach ($images as $image) { $img = wp_get_attachment_image($image['ID'], 'full', false, array('class' => 'img-responsive')); $src = wp_get_attachment_image_src($image['ID'], 'full'); } $return .= '<article class="' . implode(' ', get_post_class('entry')) . '"> <a class="swipebox" href="' . $src[0] . '"> ' . $img . ' <span class="magnifier"></span> </a> </article>'; } $return .= '</div>'; return $return; }
function st_list_hotel_related($attr, $content = false) { $data_vc = STHotel::get_taxonomy_and_id_term_tour(); $param = array('title' => '', 'sort_taxonomy' => '', 'posts_per_page' => 3, 'orderby' => 'ID', 'order' => 'DESC', 'font_size' => '3', 'number_of_row' => 1); $param = array_merge($param, $data_vc['list_id_vc']); $data = shortcode_atts($param, $attr, 'st_list_hotel_related'); extract($data); $page = STInput::request('paged'); if (!$page) { $page = get_query_var('paged'); } $query = array('post_type' => 'st_hotel', 'posts_per_page' => $posts_per_page, 'post_status' => 'publish', 'paged' => $page, 'order' => $order, 'orderby' => $orderby, 'post__not_in' => array(get_the_ID())); if (!empty($sort_taxonomy)) { if (isset($attr["id_term_" . $sort_taxonomy])) { $terms_post = wp_get_post_terms(get_the_ID(), $sort_taxonomy, array('fields' => 'ids')); $id_term = $attr["id_term_" . $sort_taxonomy]; $id_term = explode(',', $id_term); $terms = array(); foreach ($id_term as $key => $value) { if (in_array($value, $terms_post)) { $terms[] = $value; } } if ($terms) { $query['tax_query'] = array(array('taxonomy' => $sort_taxonomy, 'field' => 'id', 'terms' => $terms)); } } } $r = "<div class='list_hotel_related'>" . st()->load_template('vc-elements/st-list-hotel/loop-hot', 'deals', array('query' => new Wp_Query($query))) . "</div>"; wp_reset_query(); if (!empty($title) and !empty($r)) { $r = '<h' . $font_size . '>' . $title . '</h' . $font_size . '>' . $r; } return $r; }
public function init() { global $post; $this->objValues = array(); if (isset($post)) { $terms = wp_get_post_terms($post->ID, $this->getName(), array("fields" => "all")); foreach ($terms as $n => $term) { $this->values[] = $term->slug; $this->valuesId[] = $term->term_id; $this->objValues[$term->slug] = $term; } } $all = $this->buildTerms(get_terms($this->getName(), array('hide_empty' => 0, 'fields' => 'all'))); $childs = array(); $names = array(); foreach ($all as $term) { $names[$term['term_id']] = $term['name']; if (!isset($childs[$term['parent']]) || !is_array($childs[$term['parent']])) { $childs[$term['parent']] = array(); } $childs[$term['parent']][] = $term['term_id']; } // ksort($childs); $this->childs = $childs; $this->names = $names; }
/** * Wrapper for wp_get_post_terms which supports ordering by parent. * * NOTE: At this point in time, ordering by menu_order for example isn't possible with this function. wp_get_post_terms has no * filters which we can utilise to modify it's query. https://core.trac.wordpress.org/ticket/19094 * * @param int $product_id * @param string $taxonomy * @param array $args * @return array */ function wc_get_product_terms($product_id, $taxonomy, $args = array()) { if (!taxonomy_exists($taxonomy)) { return array(); } if (empty($args['orderby']) && taxonomy_is_product_attribute($taxonomy)) { $args['orderby'] = wc_attribute_orderby($taxonomy); } // Support ordering by parent if (!empty($args['orderby']) && $args['orderby'] == 'parent') { $fields = isset($args['fields']) ? $args['fields'] : 'all'; // Unset for wp_get_post_terms unset($args['orderby']); unset($args['fields']); $terms = wp_get_post_terms($product_id, $taxonomy, $args); usort($terms, '_wc_get_product_terms_parent_usort_callback'); switch ($fields) { case 'names': $terms = wp_list_pluck($terms, 'name'); break; case 'ids': $terms = wp_list_pluck($terms, 'term_id'); break; case 'slugs': $terms = wp_list_pluck($terms, 'slug'); break; } } else { $terms = wp_get_post_terms($product_id, $taxonomy, $args); } return $terms; }
public function addClass($classes, $item) { if (!($this->postType = $this->getPostType())) { return $classes; } if ($this->isActive($item)) { $classes[] = 'current-menu-item'; } /** * Parents & ancestors */ if (count(array_intersect(array('current-menu-item', 'current-menu-parent', 'current-menu-ancestor'), $classes)) == 0) { $navMenu = wp_get_post_terms($item->ID, 'nav_menu'); if (count($navMenu) > 0) { if (isset($this->_cache[$navMenu[0]->term_id])) { $menuItems = $this->_cache[$navMenu[0]->term_id]; } else { $menuItems = wp_get_nav_menu_items($navMenu[0]->term_id); $this->_cache[$navMenu[0]->term_id] = $menuItems; } foreach ($menuItems as $menuItem) { if ($this->isActive($menuItem)) { if ($depth = $this->findActiveDepth($menuItem, $item, $menuItems)) { if ($depth == 1) { $classes[] = 'current-menu-parent'; } elseif ($depth > 1) { $classes[] = 'current-menu-ancestor'; } } } } } } return $classes; }
/** * call in loop */ function adap_sc_portfolio_item_categories() { $cats = wp_get_post_terms(get_the_ID(), array('portfolio_category'), array('hide_empty' => 0)); ?> <ul class="portfolio-item-skills"> <?php foreach ($cats as $category) { $name = $category->name; $icon_type = adap_sc_get_portfolio_cat_option('icon_type', $category->slug); $entypo_icon = adap_sc_get_portfolio_cat_option('entypo_icon', $category->slug); $fontawesome_icon = adap_sc_get_portfolio_cat_option('fontawesome_icon', $category->slug); $icon_class = _adap_sc_get_icon_class($icon_type, $fontawesome_icon, $entypo_icon); ?> <li> <?php if ($icon_class !== null) { ?> <?php _adap_category_icon($category); ?> <?php } ?> <?php echo $name; ?> </li> <?php } ?> </ul> <?php }
/** * return portfolio post taxonomies */ function fw_theme_portfolio_post_taxonomies($post_id, $return = false) { $taxonomy = 'fw-portfolio-category'; $terms = wp_get_post_terms($post_id, $taxonomy); $list = ''; $checked = false; foreach ($terms as $term) { if ($term->parent == 0) { /* if is checked parent category */ $list .= $term->slug . ', '; $checked = true; } else { $list .= $term->slug . ', '; $parent_id = $term->parent; } } if (!$checked) { /* if is not checked parent category extract this parent */ $term = get_term_by('id', $parent_id, $taxonomy); $list .= $term->slug . ', '; } if ($return) { return $list; } else { echo $list; } }
/** * @param WP_Post[] $items * @param array $categories * @param string $prefix * * @return array */ function fw_ext_portfolio_get_sort_classes(array $items, array $categories, $prefix = 'category_') { $ext_portfolio_settings = fw()->extensions->get('portfolio')->get_settings(); $taxonomy = $ext_portfolio_settings['taxonomy_name']; $classes = array(); $categories_classes = array(); foreach ($items as $key => $item) { $class_name = ''; $terms = wp_get_post_terms($item->ID, $taxonomy); foreach ($terms as $term) { foreach ($categories as $category) { if ($term->term_id == $category->term_id) { $class_name .= $prefix . $category->term_id . ' '; $categories_classes[$term->term_id] = true; } else { if (in_array($term->term_id, $category->children, true)) { $class_name .= $prefix . $category->term_id . ' '; $categories_classes[$term->term_id] = true; } } $classes[$item->ID] = $class_name; } } } return $classes; }
/** * print the filter for the portfolio * * @param array $args [description] * @return [type] [description] */ private function worklist() { // TODO: get_query_var( 'paged' ) is given by codex, but not working in this case? $paged = get_query_var('page') ? get_query_var('page') : 1; $portfolio_query = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => $this->settings['limit'] ? $this->settings['limit'] : -1, 'paged' => $paged, 'meta_key' => '_thumbnail_id')); if ($portfolio_query->have_posts()) { echo '<div class="portfolio-list">'; $i = 1; while ($portfolio_query->have_posts()) { $portfolio_query->the_post(); $data_class = ''; $terms = wp_get_post_terms(get_the_ID(), 'portfolio_category', array('fields' => 'all')); foreach ($terms as $term) { $data_class .= $term->slug . ' '; } echo '<div data-id="' . $i . '" class="item preview-box ' . $data_class . '">'; $preview_args = array('src' => false, 'width' => $this->settings['img_width'], 'height' => $this->settings['img_height'], 'crop' => true, 'effect' => $this->settings['effect'], 'module' => 'portfolio'); echo inferno_preview($preview_args); echo '</div>'; $i++; } echo '<div class="clear clearfix"></div>'; echo '</div>'; if ($this->settings['paginate'] == true) { echo '<div class="pagination">'; echo '<div class="next">'; next_posts_link(__('Older entries', 'inferno'), $portfolio_query->max_num_pages); echo '</div><div class="prev">'; previous_posts_link(__('Newer entries', 'inferno')); echo '</div>'; echo '</div>'; } } wp_reset_postdata(); }
function get_fueltype($id) { $fueltype = wp_get_post_terms($id, 'occasion_fuel'); switch ($fueltype[0]->slug) { case 'b': echo 'Benzine'; break; case 'd': echo 'Diesel'; break; case 'e': echo 'Elektra'; break; case 'g': echo 'Gas'; break; case 'h': echo 'Hybride'; break; default: echo $fueltype[0]->name; break; } unset($fueltype); }
function kad_portfolio_permalink($permalink, $post_id, $leavename) { $post = get_post($post_id); $rewritecode = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', $leavename ? '' : '%postname%', '%post_id%', '%category%', '%author%', $leavename ? '' : '%pagename%'); if ('' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft'))) { $unixtime = strtotime($post->post_date); $category = ''; if (strpos($permalink, '%category%') !== false) { $cats = wp_get_post_terms($post->ID, 'portfolio-type', array('orderby' => 'parent', 'order' => 'DESC')); if ($cats) { //usort($cats, '_usort_terms_by_ID'); // order by ID $category = $cats[0]->slug; } // show default category in permalinks, without // having to assign it explicitly if (empty($category)) { $category = 'portfolio-category'; } } $author = ''; if (strpos($permalink, '%author%') !== false) { $authordata = get_userdata($post->post_author); $author = $authordata->user_nicename; } $date = explode(" ", date('Y m d H i s', $unixtime)); $rewritereplace = array($date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->post_name, $post->ID, $category, $author, $post->post_name); $permalink = str_replace($rewritecode, $rewritereplace, $permalink); } else { // if they're not using the fancy permalink option } return $permalink; }
private function append_employee(&$employees, $i, $id, $facilities = false, $dep_dropdown = false) { if ($facilities) { $facility = get_field('employee-facility', $id); if (!$facility) { return false; } else { if (!in_array($facility->ID, $facilities)) { return false; } } } if ($dep_dropdown) { $departments = array(); $post_terms = wp_get_post_terms($id, 'department'); foreach ($post_terms as $term) { array_push($departments, $term->name); } $employees[$i]['departments'] = $departments; } $employees[$i]['name'] = get_the_title($id); $image = get_field('employee-image', $id); $employees[$i]['image'] = $image['url']; $employees[$i]['work_title'] = get_field('employee-jobtitle', $id); $employees[$i]['email'] = get_field('employee-email', $id); $employees[$i]['hide-email'] = get_field('employee-email-hide', $id); $employees[$i]['text'] = get_field('employee-textarea', $id); $phonenumbers = get_field('employee-phonenumbers', $id); if (!empty($phonenumbers)) { $employees[$i]['phone'] = $phonenumbers[0]['employee-phonenumber-number']; } }
public function metabox_information($post) { wp_enqueue_style('markoheijnen-events', plugins_url('styles.css', __FILE__)); wp_nonce_field(plugin_basename(__FILE__), 'metabox_information_nonce'); $types = wp_get_post_terms($post->ID, 'event-type', array('fields' => 'names')); $possible_types = array('heart' => 'liked-it', 'megaphone' => 'speaker', 'groups' => 'organizer', 'wordpress' => 'wordpress'); ?> <div class="event-types"> <?php foreach ($possible_types as $icon => $term_slug) { $checked = in_array($term_slug, $types) ? ' checked' : ''; ?> <label> <input type="checkbox" autocomplete="off" name="eventtypes[<?php echo $term_slug; ?> ]"<?php echo $checked; ?> > <span class="dashicons dashicons-<?php echo $icon; ?> "></span> </label> <?php } ?> </div> <?php }
function thuoctinh($name) { global $post; $attribute_name = 'pa_' . $name; //array( 'pa_nhan-hieu', 'pa_kich-co' , ); // Insert attribute names here //foreach ( $attribute_names as $attribute_name ) { $taxonomy = get_taxonomy($attribute_name); if ($taxonomy && !is_wp_error($taxonomy)) { $terms = wp_get_post_terms($post->ID, $attribute_name); $terms_array = array(); if (!empty($terms)) { foreach ($terms as $term) { $archive_link = get_term_link($term->slug, $attribute_name); if ($attribute_name == "pa_brand") { if (is_single()) { $full_line = '<a href="' . $archive_link . '">' . $term->name . '</a>'; } else { $full_line = '<a href="' . $archive_link . '">' . $term->name . '</a>'; } } else { $full_line = '<a href="' . $archive_link . '">' . $term->name . '</a>'; } array_push($terms_array, $full_line); } return implode($terms_array, ', '); } } //} }
public static function set_defaults($defaults, $form_type) { global $post; $modules = FLBuilderModel::$modules; $all_fields = self::find_fields($modules, 'defaults'); if (is_array($all_fields)) { foreach ($all_fields as $parent_form => $types) { foreach ($types as $type => $fields) { foreach ($fields as $field => $default) { if ($parent_form == $form_type) { if ($type == 'meta') { $defaults->{$field} = get_post_meta($post->ID, $default['key'], true); } if ($type == 'taxonomy') { $defaults->{$field} = wp_get_post_terms($post->ID, $default['key'], array("fields" => "ids")); } if ($type == 'wp_option') { $defaults->{$field} = get_option($default['key']); } } } } } } return $defaults; }
/** * Set Default Terms * Used in attachment-functions.php * * @since 0.1 */ function sell_media_set_default_terms($post_id, $post = null, $term_ids = null) { if (is_null($post)) { $post_type = get_post_type($post_id); } else { $post_type = $post->post_type; $post_status = $post->post_status; } if (empty($post_status)) { return; } if (empty($term_ids) || $term_ids === true) { $term_ids = sell_media_get_default_terms(); } $taxonomy = 'licenses'; $default_terms = array(); foreach ($term_ids as $term_id) { $tmp_term_id = get_term_by('id', $term_id, $taxonomy); if ($tmp_term_id) { $default_terms[] = (int) $tmp_term_id->term_id; $default_terms[] = (int) $tmp_term_id->parent; } } $defaults = array($taxonomy => $default_terms); $taxonomies = get_object_taxonomies($post_type); foreach ((array) $taxonomies as $taxonomy) { $terms = wp_get_post_terms($post_id, $taxonomy); if (empty($terms) && array_key_exists($taxonomy, $defaults)) { wp_set_object_terms($post_id, $defaults[$taxonomy], $taxonomy); } } }
function bl_ajax_get_listings() { /* ob_start(); include(plugin_dir_path( __FILE__ )."templates/ajax-single-listing.php"); return trim( ob_get_clean() ); */ $post_id = is_numeric($_POST["bl_post_id"]) ? $_POST["bl_post_id"] : false; if ($post_id) { $the_query = new WP_Query(array("post_type" => "bepro_listings", 'p' => $post_id)); while ($the_query->have_posts()) { $the_query->the_post(); ob_start(); echo '<div id="shortcode_list">'; echo result_page_back_button(); include plugin_dir_path(__FILE__) . "/templates/content-single-listing.php"; $data = ob_get_contents(); ob_clean(); } $post = get_post($post_id); $_POST["l_name"] = $post->post_title; $cats = get_terms(array('bepro_listing_types'), array('post_id' => $post_id)); $cats = wp_get_post_terms($post_id, "bepro_listing_types", array("fields" => "ids")); $term = array(); foreach ($cats as $cat) { $term[] = $cat; } $_POST["l_type"] = $term; $_REQUEST["l_type"] = $term; } else { $data = "something went wrong"; } return $data; }
/** * Return story object with properties taken from ACF Fields. * * @since 0.1.0 * @access public * * @param object $this->container Newly instantiated Story class object. * @param object $post Story post object. **/ public function map_story_basics() { // Retrieve post_id variable. $post_id = $this->container->post_id; // Map ACF variables. $acf_intro = get_post_meta($post_id, 'editorial_intro', true); $acf_language = wp_get_post_terms($post_id, 'language', true); $acf_category = wp_get_post_terms($post_id, 'category', true); $acf_has_cta = get_post_meta($post_id, 'has_cta', true); // Set editorial introduction. if (!empty($acf_intro)) { $this->set_editorial_intro($acf_intro); } // Set language. if (!empty($acf_language) && 'WP_Term' === get_class($acf_language[0])) { $this->container->language = $acf_language[0]; } // Set category. if (!empty($acf_category) && 'WP_Term' === get_class($acf_category[0])) { $this->container->category = $acf_category[0]; } // Set CTA check if (!empty($acf_has_cta)) { $this->container->has_cta = $acf_has_cta; } }
function outdoor_portfolio_item() { $portfolio_id = isset($_POST['item_id']) ? intval($_POST['item_id']) : false; if (!$portfolio_id) { echo -1; exit; } $return_data = array(); $portfolio = get_post($portfolio_id); if ($portfolio) { $return_data['title'] = $portfolio->post_title; $return_data['description'] = $portfolio->post_content; $portf_cats = wp_get_post_terms($portfolio->ID, 'portfolio-category', array('fields' => 'names')); $portf_cats_str = is_array($portf_cats) ? implode(', ', $portf_cats) : ''; $portf_cats_str = trim($portf_cats_str, ','); $return_data['category'] = $portf_cats_str; $client = get_field('client', $portfolio_id) ? get_field('client', $portfolio_id) : ''; $link = get_field('link', $portfolio_id) ? get_field('link', $portfolio_id) : ''; $gallery = get_field('gallery', $portfolio_id) ? get_field('gallery', $portfolio_id) : ''; $return_data['client'] = $client; $return_data['url'] = $link; foreach ($gallery as $photo) { $return_data['photos'][] = $photo['url']; } } echo wp_json_encode($return_data, JSON_FORCE_OBJECT); exit; }
function bbconnect_inbound_query() { $bbc_inbound = new WP_Query(array('post_type' => apply_filters('bbconnect_inbound_posts', array('bb_note')), 'post_status' => array('publish', 'private'), 'posts_per_page' => apply_filters('bbconnect_inbound_per_page', -1), 'meta_query' => array(array('key' => '_bbc_action_status', 'value' => 'archived', 'compare' => 'NOT EXISTS')))); $inbound = array(); if ($bbc_inbound->have_posts()) { while ($bbc_inbound->have_posts()) { $bbc_inbound->the_post(); global $post; // GET THE TYPE $type = apply_filters('bbconnect_inbound_type', ''); $type_label = apply_filters('bbconnect_inbound_type_label', ''); if ('bb_note' == $post->post_type) { $terms = wp_get_post_terms($post->ID, 'bb_note_type'); if (count($terms) > 0) { $term = $types[0]; $type = $term->term_slug; $type_label = $term->term_name; } else { continue; } } $user = get_userdata($post->post_author); if (!$user) { continue; } $inbound[] = array('ID' => $post->ID, 'uid' => $user->ID, 'name' => $user->first_name . ' ' . $user->last_name, 'email' => $user->user_email, 'avatar' => get_avatar($user->user_email, 32), 'website' => $user->user_url, 'title' => $post->post_title, 'content' => $post->post_content, 'date' => $post->post_date, 'type' => $type, 'type_label' => $type_label); } } return $inbound; }
/** * Get related post ids * * @param int $post_id * * @return array Post ids */ function get_related($post_id) { $related = array(); $taxonomies = get_object_taxonomies($this->post->post_type); if ($taxonomies) { foreach ($taxonomies as $taxonomy) { $terms = wp_get_post_terms($this->post->ID, $taxonomy); if ($terms) { foreach ($terms as $term) { $posts = new WP_Query(wp_parse_args(array('posts_per_page' => '-1', 'tax_query' => array(array('taxonomy' => $taxonomy, 'terms' => $term->slug, 'field' => 'slug'))), $this->args)); if ($posts->have_posts()) { while ($posts->have_posts()) { $posts->the_post(); if (!isset($related[get_the_ID()])) { $related[get_the_ID()] = 0; } $related[get_the_ID()] += 1; } } wp_reset_postdata(); } } } } //Put them in the right order and chop off what we don't need asort($related); $related = array_reverse($related, true); if ($this->args['posts_per_page'] != -1) { $related = array_chunk($related, $this->args['posts_per_page'], true); } else { $related = array($related); } return isset($related[0]) ? array_keys($related[0]) : array(); }
/** * Gets addons assigned to a product by ID * * @param int $post_id ID of the product to get addons for * @param string $prefix for addon field names. Defaults to postid- * @param bool $inc_parent Set to false to not include parent product addons. * @param bool $inc_global Set to false to not include global addons. * @return array array of addons */ function get_product_addons($post_id, $prefix = false, $inc_parent = true, $inc_global = true) { if (!$post_id) { return array(); } $addons = array(); $raw_addons = array(); $product_terms = apply_filters('get_product_addons_product_terms', wp_get_post_terms($post_id, 'product_cat', array('fields' => 'ids')), $post_id); $exclude = get_post_meta($post_id, '_product_addons_exclude_global', true); // Product Parent Level Addons if ($inc_parent && ($parent_id = wp_get_post_parent_id($post_id))) { $raw_addons[10]['parent'] = apply_filters('get_parent_product_addons_fields', get_product_addons($parent_id, $parent_id . '-', false, false), $post_id, $parent_id); } // Product Level Addons $raw_addons[10]['product'] = apply_filters('get_product_addons_fields', array_filter((array) get_post_meta($post_id, '_product_addons', true)), $post_id); // Global level addons (all products) if ('1' !== $exclude && $inc_global) { $args = array('posts_per_page' => -1, 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_key' => '_priority', 'post_type' => 'global_product_addon', 'post_status' => 'publish', 'suppress_filters' => true, 'meta_query' => array(array('key' => '_all_products', 'value' => '1'))); $global_addons = get_posts($args); if ($global_addons) { foreach ($global_addons as $global_addon) { $priority = get_post_meta($global_addon->ID, '_priority', true); $raw_addons[$priority][$global_addon->ID] = apply_filters('get_product_addons_fields', array_filter((array) get_post_meta($global_addon->ID, '_product_addons', true)), $global_addon->ID); } } // Global level addons (categories) if ($product_terms) { $args = apply_filters('get_product_addons_global_query_args', array('posts_per_page' => -1, 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_key' => '_priority', 'post_type' => 'global_product_addon', 'post_status' => 'publish', 'suppress_filters' => true, 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $product_terms, 'include_children' => false))), $product_terms); $global_addons = get_posts($args); if ($global_addons) { foreach ($global_addons as $global_addon) { $priority = get_post_meta($global_addon->ID, '_priority', true); $raw_addons[$priority][$global_addon->ID] = apply_filters('get_product_addons_fields', array_filter((array) get_post_meta($global_addon->ID, '_product_addons', true)), $global_addon->ID); } } } } ksort($raw_addons); foreach ($raw_addons as $addon_group) { if ($addon_group) { foreach ($addon_group as $addon) { $addons = array_merge($addons, $addon); } } } // Generate field names with unqiue prefixes if (!$prefix) { $prefix = apply_filters('product_addons_field_prefix', "{$post_id}-", $post_id); } foreach ($addons as $addon_key => $addon) { if (empty($addon['name'])) { unset($addons[$addon_key]); continue; } if (empty($addons[$addon_key]['field-name'])) { $addons[$addon_key]['field-name'] = sanitize_title($prefix . $addon['name']); } } return apply_filters('get_product_addons', $addons); }
public static function getFeaturesFiltered($params) { // Do not use self unset($params['feature']); $params['all'] = true; $properties = self::getFiltered($params); $all_features = self::getAllFeatures(); $nulled = false; if (empty($all_features)) { return $all_features; } foreach ($all_features as $key => $feature) { $all_features[$key]->count = 0; } foreach ($properties as $property) { $features = wp_get_post_terms($property->getId(), 'properties-features'); foreach ($all_features as $key => &$feature) { foreach ($features as $local_key => $local_feature) { if ($feature->slug == $local_feature->slug) { $feature->count += 1; } } } } foreach ($all_features as $key => $value) { if ($all_features[$key]->count == 0) { unset($all_features[$key]); } } return $all_features; }
public function start_el(&$output, $category, $depth = 0, $args = array(), $id = 0) { /** This filter is documented in wp-includes/category-template.php */ $cat_name = apply_filters('list_cats', esc_attr($category->name), $category); // Don't generate an element if the category name is empty. if (!$cat_name) { return; } $args = array('post_type' => 'document_lists', 'tax_query' => array(array('taxonomy' => 'pages', 'field' => 'id', 'terms' => $category->term_id, 'include_children' => 1))); $query = new WP_Query($args); // The Loop if ($query->have_posts()) { $output .= ' <li class="list-headings"> <h2>' . $cat_name . '</h2> '; while ($query->have_posts()) { $query->the_post(); $post_id = get_the_ID(); $terms = wp_get_post_terms($post_id, 'pages'); $post_term_id = $terms[0]->term_id; if ($post_term_id == $category->term_id) { $link = ' <h3> </h3> '; $output .= "{$link}"; } } $output .= ''; } // Restore original Post Data wp_reset_postdata(); }
public static function get($args = array()) { $wp_args = array('post_type' => $this->post_type, 'post_status' => 'publish', 'suppress_filters' => false); $query_filters = array(); // WP_Query does not accept a 'guid' param, so we filter hackishly if (isset($args['url'])) { $this->filter_data['guid'] = $args['url']; unset($args['url']); $query_filters['posts_where'][] = '_filter_where_guid'; } foreach ($query_filters as $hook => $filters) { foreach ($filters as $f) { add_filter($hook, array($this, $f)); } } // Other WP_Query args pass through $wp_args = wp_parse_args($args, $wp_args); $posts = get_posts($wp_args); foreach ($query_filters as $hook => $filters) { foreach ($filters as $f) { remove_filter($hook, array($this, $f)); } } // Fetch some handy pf-specific data if (!empty($posts)) { foreach ($posts as &$post) { $post->word_count = get_post_meta($post->ID, 'pf_feed_item_word_count', true); $post->source = get_post_meta($post->ID, 'pf_feed_item_source', true); $post->tags = wp_get_post_terms($post->ID, $this->tag_taxonomy); } } return $posts; }
/** * Get post meta * * @param string $key Meta key. Required. * @param int|null $post_id Post ID. null for current post. Optional * @param array $args Array of arguments. Optional. * * @return mixed */ function rwmb_meta($key, $args = array(), $post_id = null) { $post_id = empty($post_id) ? get_the_ID() : $post_id; $args = wp_parse_args($args, array('type' => 'text')); // Set 'multiple' for fields based on 'type' $args['multiple'] = in_array($args['type'], array('checkbox_list', 'file', 'image', 'plupload_image', 'thickbox_image')); $meta = get_post_meta($post_id, $key, !$args['multiple']); // Get uploaded files info if ('file' == $args['type']) { if (is_array($meta) && !empty($meta)) { $files = array(); foreach ($meta as $id) { $files[$id] = rwmb_file_info($id); } $meta = $files; } } elseif (in_array($args['type'], array('image', 'plupload_image', 'thickbox_image'))) { if (is_array($meta) && !empty($meta)) { global $wpdb; $meta = implode(',', $meta); // Re-arrange images with 'menu_order' $meta = $wpdb->get_col("\n\t\t\t\tSELECT ID FROM {$wpdb->posts}\n\t\t\t\tWHERE post_type = 'attachment'\n\t\t\t\tAND ID in ({$meta})\n\t\t\t\tORDER BY menu_order ASC\n\t\t\t"); $images = array(); foreach ($meta as $id) { $images[$id] = rwmb_image_info($id, $args); } $meta = $images; } } elseif ('taxonomy' == $args['type']) { $meta = emtpy($args['taxonomy']) ? array() : wp_get_post_terms($post_id, $args['taxonomy']); } return $meta; }
/** * Prints HTML with meta information for the categories, tags and comments. */ function ving_entry_footer() { global $wp_query; // Hide category and tag text for pages. if ('post' === get_post_type()) { /* translators: used between list items, there is a space after the comma */ $categories_list = get_the_category_list(esc_html__(', ', 'ving')); if ($categories_list && ving_categorized_blog()) { $post = $wp_query->post; $cat = wp_get_post_terms($post->ID, 'category'); $count = count($cat); if ($count > 1) { printf('<span class="cat-links col-lg-6 col-md-6 col-sm-6 col-xs-12"><span class="text">CATEGORIES</span>' . esc_html__('%1$s', 'ving') . '</span>', $categories_list); // WPCS: XSS OK. } else { printf('<span class="cat-links col-lg-6 col-md-6 col-sm-6 col-xs-12"><span class="text">CATEGORY</span>' . esc_html__('%1$s', 'ving') . '</span>', $categories_list); // WPCS: XSS OK. } } /* translators: used between list items, there is a space after the comma */ $tags_list = get_the_tag_list('', esc_html__(', ', 'ving')); if ($tags_list) { printf('<span class="tags-links col-lg-5 col-md-5 col-sm-5 col-xs-12"><span class="text">TAGS</span>' . esc_html__('%1$s', 'ving') . '</span>', $tags_list); // WPCS: XSS OK. } } if (!is_single() && !post_password_required() && (comments_open() || get_comments_number())) { echo '<span class="comments-link">'; comments_popup_link(esc_html__('Leave a comment', 'ving'), esc_html__('1 Comment', 'ving'), esc_html__('% Comments', 'ving')); echo '</span>'; } edit_post_link(sprintf(esc_html__('Edit %s', 'ving'), the_title('<span class="screen-reader-text">"', '"</span>', false)), '<span class="edit-link">', '</span>'); }
/** * @param int $id * * @throws \Exception * * @return \stdClass(); */ public function retrieve($id) { $post = get_post($id); if (null === $post) { throw new \Exception('Vehicle not found'); } $data = new \stdClass(); $pm_prefix = 'wpcm_'; $data->id = $post->ID; $data->short_description = $post->post_excerpt; $data->condition = get_post_meta($post->ID, $pm_prefix . 'condition', true); $data->make = get_post_meta($post->ID, $pm_prefix . 'make', true); $data->model = get_post_meta($post->ID, $pm_prefix . 'model', true); $data->frdate = new \DateTime(get_post_meta($post->ID, $pm_prefix . 'frdate', true)); $data->price = get_post_meta($post->ID, $pm_prefix . 'price', true); $data->color = get_post_meta($post->ID, $pm_prefix . 'color', true); $data->mileage = get_post_meta($post->ID, $pm_prefix . 'mileage', true); $data->fuel_type = get_post_meta($post->ID, $pm_prefix . 'fuel_type', true); $data->transmission = get_post_meta($post->ID, $pm_prefix . 'transmission', true); $data->engine = get_post_meta($post->ID, $pm_prefix . 'engine', true); $data->body_style = get_post_meta($post->ID, $pm_prefix . 'body_style', true); $data->doors = get_post_meta($post->ID, $pm_prefix . 'doors', true); $data->features = wp_get_post_terms($post->ID, Taxonomies::FEATURES, array('fields' => 'names')); // get product gallery $product_image_gallery = ''; if (metadata_exists('post', $post->ID, '_car_gallery')) { $product_image_gallery = get_post_meta($post->ID, '_car_gallery', true); } // set attachments ids $data->gallery_attachment_ids = array_filter(explode(',', $product_image_gallery)); return $data; }
public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { // get current menu id if (!$this->current_menu) { $menu = wp_get_post_terms($item->ID, 'nav_menu'); if (!empty($menu[0])) { $this->current_menu = $menu[0]->term_id; } if (!$this->current_menu && $_REQUEST['menu']) { $this->current_menu = $_REQUEST['menu']; } } $item_output = ''; parent::start_el($item_output, $item, $depth, $args, $id); // add new fields before <div class="menu-item-actions description-wide submitbox"> $fields = $this->get_custom_fields($item, $depth); // nav menu hook support decided by the community of plugin authors ob_start(); do_action('wp_nav_menu_item_custom_fields', $item->ID, $item, $depth, $args); $fields .= ob_get_clean(); if ($fields) { $item_output = preg_replace('/(?=<div[^>]+class="[^"]*submitbox)/', $fields, $item_output); } $output .= $item_output; }
/** * Add breadcrumbs functionality to your WordPress theme * * Once you have included the function in your functions.php file * you can then place the following anywhere in your theme templates * if(function_exists('bootstrap_breadcrumbs')) bootstrap_breadcrumbs(); * * credit to: c.bavota - http://bavotasan.com (thanks for the code start) */ function bootstrap_breadcrumbs() { echo '<ol class="breadcrumb">'; echo '<li><a href="' . home_url('/') . '">Home</a></li>'; // are we at "blog home"? if (is_home()) { echo '<li><a href="#">Blogs</a></li>'; } // where else do we want breadcrumbs if (!is_page_template('pt-home.php') && !is_home()) { // check if we're in a commerce plugin if (function_exists('is_woocommerce') && is_woocommerce()) { echo '<li><a href="/publications/order/">Shop</a></li>'; $product_cats = wp_get_post_terms(get_the_ID(), 'product_cat'); echo '<li><a href="/publications/order/' . str_replace(" ", "-", $product_cats[0]->name) . '">' . $product_cats[0]->name . '</a></li>'; } // breadcrumb wordpress structures if (is_category() || is_single() || is_single('aof')) { if (get_the_category()) { $category = get_the_category(); echo '<li><a href="/blog/category/' . str_replace(" ", "-", $category[0]->cat_name) . '">' . $category[0]->cat_name . '</a></li>'; } if (is_single()) { echo '<li class="active">'; the_title(); echo '</li>'; } } elseif (is_page()) { echo '<li class="active">'; the_title(); echo '</li>'; } } echo '</ol>'; }