function hocwp_get_all_mo_posts($args = array()) { $defaults = array('post_type' => 'hocwp_mo', 'posts_per_page' => -1); $args = wp_parse_args($args, $defaults); $query = hocwp_query($args); return $query->posts; }
function hocwp_get_post_by_slug($slug, $post_type = 'post') { $args = array('name' => $slug, 'post_type' => $post_type, 'posts_per_page' => 1); $query = hocwp_query($args); return array_shift($query->posts); }
<div class="<?php hocwp_wrap_class(); ?> "> <?php hocwp_breadcrumb(); hocwp_theme_site_main_before(); if (is_page()) { echo hocwp_wrap_tag(get_the_title(), 'h1', 'page-title entry-title'); } $args = array('post_type' => 'post', 'paged' => hocwp_get_paged()); $query = hocwp_query($args); if ($query->have_posts()) { echo '<div class="loop-posts">'; while ($query->have_posts()) { $query->the_post(); hocwp_theme_get_loop('post'); } wp_reset_postdata(); echo '</div>'; hocwp_pagination(array('query' => $query)); } else { hocwp_theme_get_content_none(); } hocwp_theme_site_main_after(); get_sidebar('secondary'); ?> </div>
public function widget($args, $instance) { $this->instance = $instance; global $post; $title = hocwp_widget_title($args, $instance, false); $post_type = $this->get_post_type_from_instance($instance); $post_types = array(); foreach ($post_type as $fvdata) { $ptvalue = isset($fvdata['value']) ? $fvdata['value'] : ''; if (!empty($ptvalue)) { $post_types[] = $ptvalue; } } $number = isset($instance['number']) ? $instance['number'] : $this->args['number']; $by = isset($instance['by']) ? $instance['by'] : $this->args['by']; $category = isset($instance['category']) ? $instance['category'] : json_encode($this->args['category']); $category = hocwp_json_string_to_array($category); $excerpt_length = isset($instance['excerpt_length']) ? $instance['excerpt_length'] : $this->args['excerpt_length']; $content_class = 'widget-content'; $slider = hocwp_get_value_by_key($instance, 'slider', hocwp_get_value_by_key($this->args, 'slider')); $title_length = hocwp_get_value_by_key($instance, 'title_length', hocwp_get_value_by_key($this->args, 'title_length')); $hide_thumbnail = hocwp_get_value_by_key($instance, 'hide_thumbnail', hocwp_get_value_by_key($this->args, 'hide_thumbnail')); $widget_title_link_category = hocwp_get_value_by_key($instance, 'widget_title_link_category', hocwp_get_value_by_key($this->args, 'widget_title_link_category')); $category_as_widget_title = hocwp_get_value_by_key($instance, 'category_as_widget_title', hocwp_get_value_by_key($this->args, 'category_as_widget_title')); if ((bool) $slider) { hocwp_add_string_with_space_before($content_class, 'post-slider'); } if ('category' == $by && (bool) $widget_title_link_category) { $cvalue = current($category); $term_id = isset($cvalue['value']) ? $cvalue['value'] : ''; $term_id = absint($term_id); if ($term_id > 0) { $taxonomy = isset($cvalue['taxonomy']) ? $cvalue['taxonomy'] : ''; $link = new HOCWP_HTML('a'); $link->set_class('term-link'); $link->set_href(get_term_link($term_id, $taxonomy)); if ((bool) $category_as_widget_title) { $term = get_term($term_id, $taxonomy); $title = $term->name; } else { $title = hocwp_get_value_by_key($instance, 'title'); } $link->set_text($title); $title = hocwp_get_value_by_key($args, 'before_title') . $link->build() . hocwp_get_value_by_key($args, 'after_title'); } } $query_args = array('posts_per_page' => $number, 'post_type' => $post_types); $w_query = new WP_Query(); $get_by = false; switch ($by) { case 'recent': $get_by = true; break; case 'modified': case 'recent_modified': $get_by = true; $query_args['orderby'] = 'modified'; $query_args['order'] = 'DESC'; break; case 'rand': case 'random': $get_by = true; $query_args['orderby'] = 'rand'; break; case 'most_comment': case 'comment_count': case 'comment': $get_by = true; $query_args['orderby'] = 'comment_count'; break; case 'category': foreach ($category as $cvalue) { $term_id = isset($cvalue['value']) ? $cvalue['value'] : ''; $term_id = absint($term_id); if ($term_id > 0) { $taxonomy = isset($cvalue['taxonomy']) ? $cvalue['taxonomy'] : ''; if (!empty($taxonomy)) { $tax_item = array('taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $term_id); $query_args = hocwp_query_sanitize_tax_query($tax_item, $query_args); $get_by = true; } } } break; case 'related': $get_by = true; break; case 'like': $get_by = true; $query_args['meta_key'] = 'likes'; $query_args['orderby'] = 'meta_value_num'; break; case 'view': $get_by = true; $query_args['meta_key'] = 'views'; $query_args['orderby'] = 'meta_value_num'; break; case 'featured': $get_by = true; hocwp_query_sanitize_featured_args($query_args); break; case 'favorite': break; case 'rate': break; } $get_by = apply_filters('hocwp_widget_post_get_by_check_status', $get_by, $args, $instance, $this); if ($get_by) { $query_args = apply_filters('hocwp_widget_post_query_args', $query_args, $args, $instance, $this); if ('related' == $by) { $w_query = hocwp_query_related_post($query_args); } else { $w_query = hocwp_query($query_args); } } $widget_html = hocwp_get_value_by_key($args, 'before_widget') . $title; $widget_html .= '<div class="' . $content_class . '">'; $widget_post_pre_html = apply_filters('hocwp_widget_post_pre_html', '', $args, $instance, $this); if (!empty($widget_post_pre_html)) { $widget_html .= $widget_post_pre_html; } else { if ($w_query->have_posts()) { $widget_html .= apply_filters('hocwp_widget_post_before_loop', '', $args, $instance, $this); if ((bool) $slider) { $four_posts = array_slice($w_query->posts, 0, 4); $next_posts = array_slice($w_query->posts, 4, absint($w_query->post_count - 4)); $widget_content = apply_filters('hocwp_widget_post_pre_slider_html', '', $args, $instance, $this); if (empty($widget_content)) { $carousel_id = $this->id; $carousel_id = hocwp_sanitize_id($carousel_id); $count = 0; ob_start(); ?> <div id="<?php echo $carousel_id; ?> " class="carousel slide" data-ride="carousel"> <div class="carousel-inner" role="listbox"> <?php foreach ($four_posts as $post) { setup_postdata($post); $class = 'item'; if (0 == $count) { hocwp_add_string_with_space_before($class, 'active'); } ?> <div class="<?php echo $class; ?> "> <?php hocwp_article_before(); do_action('hocwp_widget_post_slider_before_post', $args, $instance, $this); if (!(bool) $hide_thumbnail) { if ('coupon' == $post->post_type) { $store = hocwp_get_coupon_store($post->ID); echo '<div class="text-center store-logo">'; hocwp_term_the_thumbnail(array('term' => $store, 'width' => 180, 'height' => 110)); echo '</div>'; } else { hocwp_post_thumbnail(array('width' => 300, 'height' => 200)); } } do_action('hocwp_widget_post_slider_before_post_title', $args, $instance, $this); hocwp_post_title_link(array('title' => hocwp_substr(get_the_title(), $title_length))); do_action('hocwp_widget_post_slider_after_post_title', $args, $instance, $this); hocwp_entry_summary($excerpt_length); do_action('hocwp_widget_post_slider_after_post', $args, $instance, $this); hocwp_article_after(); ?> </div> <?php $count++; } wp_reset_postdata(); ?> </div> <ol class="carousel-indicators list-inline list-unstyled"> <?php $count = count($four_posts); for ($i = 0; $i < $count; $i++) { $indicator_class = 'indicator-item'; if (0 == $i) { hocwp_add_string_with_space_before($indicator_class, 'active'); } ?> <li data-target="#<?php echo $carousel_id; ?> " data-slide-to="<?php echo $i; ?> " class="<?php echo $indicator_class; ?> "> <span><?php echo $i + 1; ?> </span> </li> <?php } ?> </ol> <a class="left carousel-control" href="#<?php echo $carousel_id; ?> " role="button" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> <span class="sr-only"><?php _e('Previous', 'hocwp-theme'); ?> </span> </a> <a class="right carousel-control" href="#<?php echo $carousel_id; ?> " role="button" data-slide="next"> <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> <span class="sr-only"><?php _e('Next', 'hocwp-theme'); ?> </span> </a> </div> <?php $widget_content = ob_get_clean(); if (hocwp_array_has_value($next_posts)) { $w_query->posts = $next_posts; $w_query->post_count = count($next_posts); ?> <div class="more-posts"> <?php $widget_content .= $this->list_post_html($args, $instance, $w_query); ?> </div> <?php } } $widget_content = apply_filters('hocwp_widget_post_slider_html', $widget_content, $args, $instance, $this); $widget_html .= $widget_content; } else { $widget_html .= $this->list_post_html($args, $instance, $w_query); } $widget_html .= apply_filters('hocwp_widget_post_after_loop', '', $args, $instance, $this); } else { $widget_html .= '<p class="nothing-found">' . __('Nothing found!', 'hocwp-theme') . '</p>'; } } $widget_html = apply_filters('hocwp_widget_post_html', $widget_html, $args, $instance, $this); $widget_html .= '</div>'; $widget_html .= hocwp_get_value_by_key($args, 'after_widget'); echo $widget_html; }
function hocwp_theme_more_product_meta_boxes_init($post_type, $post) { if (hocwp_wc_installed()) { $args = array('posts_per_page' => -1, 'post_type' => 'hocwp_product_tab'); $query = hocwp_query($args); if ($query->have_posts()) { hocwp_theme_meta_product_tab_field_box_helper($query->posts); } } else { if (hocwp_is_shop_site()) { hocwp_shop_product_meta_boxes($post_type, $post); } } }
function hocwp_query_all($post_type) { $args = array('post_type' => $post_type, 'posts_per_page' => -1); if ('page' == $post_type) { $args['orderby'] = 'title'; $args['order'] = 'ASC'; } return hocwp_query($args); }
function hocwp_setup_theme_register_user_sidebar() { $args = array('post_type' => 'hocwp_sidebar', 'posts_per_page' => -1, 'meta_query' => array(array('relation' => 'OR', array('key' => 'sidebar_default', 'compare' => 'NOT EXISTS'), array('key' => 'sidebar_default', 'compare' => '!=', 'type' => 'numeric')))); $query = hocwp_query($args); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $post_id = get_the_ID(); $current = get_post($post_id); $info = hocwp_get_sidebar_info($current); if (!$info['active'] || $info['default']) { continue; } hocwp_register_sidebar($info['id'], $info['name'], $info['description'], $info['tag']); } wp_reset_postdata(); } }
function hocwp_get_current_new_post() { global $pagenow; $result = null; if ('post-new.php' == $pagenow) { $query_args = array('post_status' => 'auto-draft', 'orderby' => 'date', 'order' => 'desc', 'posts_per_page' => 1, 'cache' => false); $post_type = hocwp_get_current_post_type(); if (!empty($post_type)) { $query_args['post_type'] = $post_type; } $query = hocwp_query($query_args); $result = array_shift($query->posts); } return $result; }
function hocwp_setup_theme_woocommerce_product_tabs($tabs) { $args = array('posts_per_page' => -1, 'post_type' => 'hocwp_product_tab'); $query = hocwp_query($args); if ($query->have_posts()) { foreach ($query->posts as $tab) { $id = hocwp_sanitize_id($tab->post_name); $tabs[$id] = array('title' => $tab->post_title, 'priority' => 20, 'callback' => 'hocwp_setup_theme_woocommerce_product_tabs_callback'); } } return $tabs; }
function hocwp_field_select_post($args = array()) { $post_type = hocwp_get_value_by_key($args, 'post_type', 'post'); $query = hocwp_query(array('post_type' => $post_type)); $choose_text = __('Choose post', 'hocwp-theme'); $choose_text = apply_filters('hocwp_theme_select_post_text', $choose_text); $all_option = '<option value="0">-- ' . $choose_text . ' --</option>'; $value = isset($args['value']) ? $args['value'] : ''; while ($query->have_posts()) { $query->the_post(); $post_id = get_the_ID(); $all_option .= '<option value="' . esc_attr($post_id) . '" ' . selected($value, $post_id, false) . '>' . get_the_title() . '</option>'; } wp_reset_postdata(); $args['all_option'] = $all_option; hocwp_field_select($args); }