本文整理汇总了PHP中wp_reset_postdata函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_reset_postdata函数的具体用法?PHP wp_reset_postdata怎么用?PHP wp_reset_postdata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_reset_postdata函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: charity_vc_our_mission
function charity_vc_our_mission($atts, $content = null)
{
extract(shortcode_atts(array('our_mission' => ''), $atts));
$page_id = get_page_by_title($our_mission);
$missionQuery = new WP_Query(array("page_id" => $page_id->ID));
if ($missionQuery->have_posts()) {
$missionQuery->the_post();
$url = wp_get_attachment_image_src(get_post_thumbnail_id($page_id->ID), array(1143, 479));
?>
<!-- Save Lives Section Start Here-->
<section class="save-lives text-center parallax" style="background-image: url('<?php
echo esc_url($url[0]);
?>
')">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3">
<header class="page-header">
<h2><?php
the_title();
?>
</h2>
<?php
the_content();
?>
</header>
</div>
</div>
</div>
</section>
<!-- Save Lives Section Start Here-->
<?php
}
wp_reset_postdata();
}
示例2: widget
function widget($args, $instance)
{
ob_start();
extract($args);
$title = !empty($instance['title']) ? esc_attr($instance['title']) : __('Custom Menu', 'zn_framework');
$title = apply_filters('widget_title', $title, $instance, $this->id_base);
$menu = isset($instance['menu']) ? esc_attr($instance['menu']) : '';
$style = isset($instance['style']) ? esc_attr($instance['style']) : '';
$columns = isset($instance['columns']) ? esc_attr($instance['columns']) : '';
if (empty($menu)) {
echo 'Please edit the widget and select at least one menu';
return;
}
echo $before_widget;
if ($title) {
echo $before_title . $title . $after_title;
}
$menu_items = wp_get_nav_menu_items($menu);
echo '<ul class="menu-' . $menu . ' ' . $style . ' clearfix ">';
//row
foreach ((array) $menu_items as $key => $menu_item) {
$title = $menu_item->title;
$url = $menu_item->url;
echo '<li class="' . $columns . '"><a href="' . $url . '">' . $title . '</a></li>';
}
echo '</ul>';
echo $after_widget;
// Reset the global $the_post as this query will have stomped on it
wp_reset_postdata();
}
示例3: bap_ajaxP_loop
function bap_ajaxP_loop($offset = '')
{
global $wp_query;
$paged = get_query_var('page') ? get_query_var('page') : 1;
$do_not_duplicate = array();
// OFFSET SETTING
if (!$offset == '' || !$offset == '0') {
$argshidepost = array('numberposts' => $offset, 'post_type' => 'post', 'post_status' => 'publish');
$hide_to_array = get_posts($argshidepost);
// HIDE OFFSETED POSTS
if ($hide_to_array) {
foreach ($hide_to_array as $post) {
$do_not_duplicate[] = $post->ID;
}
}
}
$argsmain = array('post_type' => 'post', 'post_status' => 'publish', 'paged' => $paged, 'order' => 'DESC', 'post__not_in' => $do_not_duplicate);
$wp_query = new WP_Query($argsmain);
if ($wp_query->have_posts()) {
echo '<section id="' . bap_get_option_text('bap_loopContainer') . '">';
while ($wp_query->have_posts()) {
$wp_query->the_post();
get_template_part('partials/listitem');
}
echo '</section>';
}
wp_reset_postdata();
}
示例4: rec_epl_lu_single_download
function rec_epl_lu_single_download()
{
global $post, $epl_settings;
$unique_id = get_post_meta($post->ID, 'property_unique_id', true);
$tab_title = isset($epl_settings['epl_lu_group_title']) ? __($epl_settings['epl_lu_group_title'], 'epl') : __('Extra Info', 'epl');
$query = new WP_Query(array('post_type' => 'listing_unlimited', 'meta_query' => array(array('key' => 'property_unique_id', 'value' => $unique_id, 'compare' => '=='))));
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$link = get_post_meta($post->ID, 'listing_unlimited_pdf', true);
?>
<div style="xxxdisplay:none" class="rec-panel-section-32 xxxfancybox-hidden">
<div id="xxxfancyboxID-section-32">
<?php
echo do_shortcode('[gravityform id="21" title="false" description="false" tabindex="33"]');
?>
</div>
</div>
<!--<h5 class="widget-sub-title download"><a href="#fancyboxID-section-32" class="rec-panel-section-32-popout-fancybox fancybox"><i class="fa fa-file-pdf-o"></i> Download Section 32</a></h5>-->
<?php
}
}
wp_reset_postdata();
}
示例5: ebor_testimonial_shortcode
/**
* The Shortcode
*/
function ebor_testimonial_shortcode($atts)
{
extract(shortcode_atts(array('pppage' => '999', 'filter' => 'all', 'type' => 'carousel-3col'), $atts));
/**
* Initial query args
*/
$query_args = array('post_type' => 'testimonial', 'posts_per_page' => $pppage);
if (!($filter == 'all')) {
if (function_exists('icl_object_id')) {
$filter = (int) icl_object_id($filter, 'testimonial_category', true);
}
$query_args['tax_query'] = array(array('taxonomy' => 'testimonial_category', 'field' => 'id', 'terms' => $filter));
}
/**
* Finally, here's the query.
*/
global $wp_query;
$wp_query = new WP_Query($query_args);
ob_start();
get_template_part('loop/loop-testimonial', $type);
wp_reset_postdata();
$output = ob_get_contents();
ob_end_clean();
return $output;
}
示例6: widget
function widget($args, $instance)
{
$cache = wp_cache_get('widget_dt_slider', 'widget');
if (!is_array($cache)) {
$cache = array();
}
if (!isset($args['widget_id'])) {
$args['widget_id'] = $this->id;
}
if (isset($cache[$args['widget_id']])) {
echo $cache[$args['widget_id']];
return;
}
ob_start();
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? __('', 'engine') : $instance['title'], $instance, $this->id_base);
$category = empty($instance['category']) ? '' : $instance['category'];
$qty = empty($instance['qty']) ? '3' : $instance['qty'];
$excerpt_length = empty($instance['excerpt_length']) ? '0' : $instance['excerpt_length'];
$r = new WP_Query(array('posts_per_page' => $qty, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'category__in' => explode(',', $category)));
if ($r->have_posts()) {
?>
<?php
echo $before_widget;
echo do_shortcode('[engine_slider title="' . $title . '" category="' . $category . '" qty="' . $qty . '" autoplay="0" random="0" thumb_size="small" excerpt_length="' . $excerpt_length . '"]');
echo $after_widget;
// Reset the global $the_post as this query will have stomped on it
wp_reset_postdata();
}
$cache[$args['widget_id']] = ob_get_flush();
wp_cache_set('widget_dt_slider', $cache, 'widget');
}
示例7: widget
public function widget($args, $instance)
{
extract($args);
$title = apply_filters('widget_title', $instance['title']);
echo $before_widget;
if (!empty($title)) {
echo $before_title . $title . $after_title;
}
$numberposts = isset($instance['numberposts']) ? $instance['numberposts'] : 1;
$termargs = array('post_type' => 'glossary', 'post_status' => 'publish', 'numberposts' => $numberposts, 'orderby' => 'rand');
if ($group = $instance['group']) {
$termargs['tax_query'] = array(array('taxonomy' => 'wpglossarygroup', 'field' => 'slug', 'terms' => $group));
}
$terms = get_posts($termargs);
if ($terms && count($terms)) {
echo '<ul class="wpglossary widget-list">';
foreach ($terms as $term) {
setup_postdata($term);
$title = '<a href="' . apply_filters('wpg_term_link', get_post_permalink($term->ID)) . '">' . get_the_title($term->ID) . '</a>';
$desc = '';
$display = $instance['display'];
if ($display && $display != 'title') {
$desc = $display == 'full' ? apply_filters('the_content', get_the_content(), $main = false) : wpautop(get_the_excerpt());
$desc = '<br>' . $desc;
}
echo '<li>' . $title . $desc . '</li>';
}
wp_reset_postdata();
echo '</ul>';
} else {
echo '<em>' . __('No terms available', 'wp-glossary') . '</em>';
}
echo $after_widget;
}
示例8: load_more_posts_callback
function load_more_posts_callback()
{
check_ajax_referer('pan_travel_blog', 'token');
try {
$offset = $_POST['offset'];
$number = $_POST['number'];
$loop = new WP_Query(array('post_type' => 'travel_blogs', 'post_status' => 'publish', 'order' => 'DESC', 'orderby' => 'meta_value', 'meta_key' => 'travel_blog_start_date', 'offset' => $offset, 'posts_per_page' => $number));
if ($loop->have_posts()) {
while ($loop->have_posts()) {
$loop->the_post();
?>
<?php
get_template_part('parts/content', 'travelblog');
?>
<?php
}
} else {
?>
<p><?php
_e('Sorry, no posts matched your criteria.');
?>
</p>
<?php
}
wp_reset_postdata();
} catch (Exception $e) {
echo 'Errors';
}
wp_die();
}
示例9: widget
public function widget($args, $instance)
{
?>
<?php
echo $args['before_widget'];
?>
<?php
echo $args['before_title'];
echo $instance['title'];
echo $args['after_title'];
?>
<div class="list-group">
<?php
$arg = array('posts_per_page' => 5, 'post_type' => 'post', 'orderby' => 'date', 'order' => 'DESC');
$newposts = new WP_Query($arg);
while ($newposts->have_posts()) {
$newposts->the_post();
?>
<a class="list-group-item" href="<?php
the_permalink();
?>
"><?php
the_title();
?>
</a>
<?php
}
wp_reset_postdata();
?>
</div>
<?php
echo $args['after_widget'];
?>
<?php
}
示例10: estimate_embed
public static function estimate_embed($atts = array())
{
do_action('sprout_invoices_estimate_embed');
$estimate_id = 0;
// Make sure id given is for an invoice
if (isset($atts['id'])) {
$estimate_id = (int) $atts['id'];
}
if (isset($_GET['si_id'])) {
$estimate_id = (int) $_GET['si_id'];
}
if (SI_Estimate::POST_TYPE !== get_post_type($estimate_id)) {
return;
}
// enqueue style
self::frontend_enqueue();
// Show snippet view or not.
$embed_view = '';
if (isset($atts['snippet']) && 'true' === $atts['snippet']) {
$embed_view = '-snippet';
}
self::remove_actions();
// Setup global post for filters and functions to work
global $post;
$post = get_post($estimate_id);
setup_postdata($post);
$estimate = SI_Estimate::get_instance($estimate_id);
$line_items = $estimate->get_line_items();
$view = self::load_addon_view_to_string('estimates/embed' . $embed_view, array('id' => $estimate_id, 'line_items' => $line_items, 'prev_type' => '', 'totals' => SI_Line_Items::line_item_totals($estimate_id)), false);
// reset to the original post
wp_reset_postdata();
return $view;
}
示例11: widget
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget($args, $instance)
{
echo $args['before_widget'];
$display_title = !empty($instance['display_title']) ? $instance['display_title'] : '';
$numberofposts = !empty($instance['numberofposts']) ? absint($instance['numberofposts']) : '';
if ($display_title == 'on') {
if (!empty($instance['title'])) {
echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
}
}
$post_query_args = array('post_type' => array('post'), 'pagination' => false, 'posts_per_page' => $numberofposts, 'ignore_sticky_posts' => true, 'cache_results' => true, 'update_post_meta_cache' => true, 'update_post_term_cache' => true);
$post_query = new WP_Query($post_query_args);
if ($post_query->have_posts()) {
while ($post_query->have_posts()) {
$post_query->the_post();
global $post;
$output = '';
$output .= '<div class="widget-recent-post clearfix">';
$output .= has_post_thumbnail($post->ID) ? '<div class="recent-post-image">' : '';
$output .= has_post_thumbnail($post->ID) ? get_the_post_thumbnail($post->ID, 'illdy-widget-recent-posts') : '';
$output .= has_post_thumbnail($post->ID) ? '</div><!--/.recent-post-image-->' : '';
$output .= '<a href="' . esc_url(get_the_permalink()) . '" title="' . esc_attr(get_the_title()) . '" class="recent-post-title">' . esc_html(get_the_title()) . '</a>';
$output .= '<a href="' . esc_url(get_the_permalink()) . '" title="' . __('More...', 'illdy') . '" class="recent-post-button">' . __('More...', 'illdy') . '</a>';
$output .= '</div><!--/.widget-recent-post.clearfix-->';
echo $output;
}
} else {
echo __('No posts found.', 'illdy');
}
wp_reset_postdata();
echo $args['after_widget'];
}
示例12: widget
/**
* widget function.
*
* @see WP_Widget
* @access public
* @param array $args
* @param array $instance
* @return void
*/
public function widget($args, $instance)
{
global $comments, $comment, $woocommerce;
if ($this->get_cached_widget($args)) {
return;
}
ob_start();
extract($args);
$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
$number = absint($instance['number']);
$query_args = array('posts_per_page' => $number, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'post__in' => $viewed_products, 'orderby' => 'rand');
$query_args['meta_query'] = array();
$query_args['meta_query'][] = WC()->query->stock_status_meta_query();
$query_args['meta_query'] = array_filter($query_args['meta_query']);
$r = new WP_Query($query_args);
if ($r->have_posts()) {
echo $before_widget;
if ($title) {
echo $before_title . $title . $after_title;
}
echo '<ul class="product_list_widget">';
while ($r->have_posts()) {
$r->the_post();
wc_get_template('content-widget-product.php');
}
echo '</ul>';
echo $after_widget;
}
wp_reset_postdata();
$content = ob_get_clean();
echo $content;
}
示例13: td_events_api
function td_events_api()
{
$events = array();
$start = isset($_GET['start']) ? $_GET['start'] : '';
$end = isset($_GET['end']) ? $_GET['end'] : '';
$args = array('post_type' => 'event');
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$parent = get_post(get_post_meta(get_the_ID(), 'tdec_product', true));
$dates = get_post_meta(get_the_ID(), 'tdec_dates', true);
$color = get_post_meta(get_the_ID(), 'tdec_color', true);
if (is_array($dates)) {
foreach ($dates as $date) {
$event = array('title' => $parent->post_title, 'start' => date('c', $date['start']), 'end' => date('c', $date['end']), 'url' => get_permalink($parent->ID), 'backgroundColor' => $color);
$events[] = $event;
}
}
}
}
wp_reset_postdata();
echo json_encode($events);
die;
}
示例14: pmxi_findDuplicates
/**
* Find duplicates according to settings
*/
function pmxi_findDuplicates($articleData, $custom_duplicate_name = '', $custom_duplicate_value = '', $duplicate_indicator = 'title')
{
global $wpdb;
if ('custom field' == $duplicate_indicator) {
$duplicate_ids = array();
if (!empty($articleData['post_type'])) {
$post_types = (class_exists('PMWI_Plugin') and $articleData['post_type'] == 'product') ? array('product', 'product_variation') : array($articleData['post_type']);
$args = array('post_type' => $post_types, 'post_status' => array('any'), 'meta_query' => array(array('key' => trim($custom_duplicate_name), 'value' => htmlspecialchars(trim($custom_duplicate_value)))), 'order' => 'ASC', 'orderby' => 'ID');
$query = new WP_Query($args);
if ($query->have_posts()) {
$duplicate_ids[] = $query->post->ID;
}
wp_reset_postdata();
if (empty($duplicate_ids)) {
$query = $wpdb->get_results($wpdb->prepare("SELECT SQL_CALC_FOUND_ROWS " . $wpdb->posts . ".ID FROM " . $wpdb->posts . " INNER JOIN " . $wpdb->postmeta . " ON (" . $wpdb->posts . ".ID = " . $wpdb->postmeta . ".post_id) WHERE 1=1 AND " . $wpdb->posts . ".post_type IN ('" . implode("','", $post_types) . "') AND (" . $wpdb->posts . ".post_status = 'publish' OR " . $wpdb->posts . ".post_status = 'future' OR " . $wpdb->posts . ".post_status = 'draft' OR " . $wpdb->posts . ".post_status = 'pending' OR " . $wpdb->posts . ".post_status = 'trash' OR " . $wpdb->posts . ".post_status = 'private') AND ( (" . $wpdb->postmeta . ".meta_key = '%s' AND CAST(" . $wpdb->postmeta . ".meta_value AS CHAR) = '%s') ) GROUP BY " . $wpdb->posts . ".ID ORDER BY " . $wpdb->posts . ".ID ASC LIMIT 0, 20", trim($custom_duplicate_name), htmlspecialchars(trim($custom_duplicate_value))));
if (!empty($query)) {
foreach ($query as $p) {
$duplicate_ids[] = $p->ID;
}
}
}
} else {
$args = array('meta_query' => array(0 => array('key' => $custom_duplicate_name, 'value' => $custom_duplicate_value, 'compare' => '=')));
$user_query = new WP_User_Query($args);
if (!empty($user_query->results)) {
foreach ($user_query->results as $user) {
$duplicate_ids[] = $user->ID;
}
} else {
$query = $wpdb->get_results($wpdb->prepare("SELECT SQL_CALC_FOUND_ROWS " . $wpdb->users . ".ID FROM " . $wpdb->users . " INNER JOIN " . $wpdb->usermeta . " ON (" . $wpdb->users . ".ID = " . $wpdb->usermeta . ".user_id) WHERE 1=1 AND ( (" . $wpdb->usermeta . ".meta_key = '%s' AND CAST(" . $wpdb->usermeta . ".meta_value AS CHAR) = '%s') ) GROUP BY " . $wpdb->users . ".ID ORDER BY " . $wpdb->users . ".ID ASC LIMIT 0, 20", $custom_duplicate_name, $custom_duplicate_value));
if (!empty($query)) {
foreach ($query as $p) {
$duplicate_ids[] = $p->ID;
}
}
}
}
return $duplicate_ids;
} elseif ('parent' == $duplicate_indicator) {
$field = 'post_title';
// post_title or post_content
return $wpdb->get_col($wpdb->prepare("\n\t\t\tSELECT ID FROM " . $wpdb->posts . "\n\t\t\tWHERE\n\t\t\t\tpost_type = %s\n\t\t\t\tAND ID != %s\n\t\t\t\tAND post_parent = %s\n\t\t\t\tAND REPLACE(REPLACE(REPLACE({$field}, ' ', ''), '\\t', ''), '\\n', '') = %s\n\t\t\t", $articleData['post_type'], isset($articleData['ID']) ? $articleData['ID'] : 0, !empty($articleData['post_parent']) ? $articleData['post_parent'] : 0, preg_replace('%[ \\t\\n]%', '', $articleData[$field])));
} else {
if (!empty($articleData['post_type'])) {
$field = 'post_' . $duplicate_indicator;
// post_title or post_content
return $wpdb->get_col($wpdb->prepare("\n\t\t\t\tSELECT ID FROM " . $wpdb->posts . "\n\t\t\t\tWHERE\n\t\t\t\t\tpost_type = %s\n\t\t\t\t\tAND ID != %s\n\t\t\t\t\tAND REPLACE(REPLACE(REPLACE({$field}, ' ', ''), '\\t', ''), '\\n', '') = %s\n\t\t\t\t", $articleData['post_type'], isset($articleData['ID']) ? $articleData['ID'] : 0, preg_replace('%[ \\t\\n]%', '', $articleData[$field])));
} else {
if ($duplicate_indicator == 'title') {
$field = 'user_login';
$u = get_user_by('login', $articleData[$field]);
return !empty($u) ? array($u->ID) : false;
} else {
$field = 'user_email';
$u = get_user_by('email', $articleData[$field]);
return !empty($u) ? array($u->ID) : false;
}
}
}
}
示例15: widget
function widget($args, $instance)
{
extract($args);
$title_widget = $instance['title_widget'];
$limit = $instance['limit'];
echo $before_widget;
echo '<h3 class="widget-title">' . $title_widget . '</h3>';
echo '<ul>';
$args = array('posts_per_page' => $limit, 'post_type' => 'coupons', 'meta_key' => 'clicks', 'orderby' => 'meta_value', 'order' => 'DESC');
$coupons = get_posts($args);
foreach ($coupons as $coupon) {
setup_postdata($coupon);
?>
<li>
<a href="<?php
echo get_permalink($coupon->ID);
?>
"><?php
echo get_the_title($coupon->ID);
?>
( <?php
echo get_post_meta($coupon->ID, 'coupon_discount', true);
?>
)</a>
</li>
<?php
}
wp_reset_postdata();
echo '</ul>';
echo $after_widget;
}