本文整理汇总了PHP中WP_Query::reset_postdata方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query::reset_postdata方法的具体用法?PHP WP_Query::reset_postdata怎么用?PHP WP_Query::reset_postdata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Query
的用法示例。
在下文中一共展示了WP_Query::reset_postdata方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _s_truncate_gallery
/**
* Truncate gallery
*
* @link
*/
function _s_truncate_gallery($atts)
{
$atts = shortcode_atts(array('total' => -1), $atts);
$args = array('p' => get_the_id());
$query = new WP_Query($args);
if ($query->have_posts()) {
$gallery_image_ids_array = array();
while ($query->have_posts()) {
$query->the_post();
if (get_post_gallery()) {
$gallery = get_post_gallery(get_the_ID(), false);
$gallery_image_ids = explode(",", $gallery['ids']);
$c = 0;
foreach ($gallery_image_ids as $gallery_image_id) {
array_push($gallery_image_ids_array, $gallery_image_id);
if (++$c == $atts['total']) {
break;
}
}
}
}
}
$query->reset_postdata();
return implode(',', $gallery_image_ids_array);
}
示例2: output
/**
* Output the metabox
*/
public static function output($post)
{
global $post, $wpdb, $thepostid;
$parent_post = false;
if (isset($_GET['post_parent']) && $_GET['post_parent'] != '') {
$parent_post = $_GET['post_parent'];
}
echo '<div class="propertyhive_meta_box">';
echo '<div class="options_group">';
// Negotiator
$negotiator_id = get_post_meta($post->ID, '_negotiator_id', TRUE);
if ($parent_post !== FALSE) {
$negotiator_id = get_post_meta($parent_post, '_negotiator_id', TRUE);
}
if ($negotiator_id == '') {
// if neg isn't set then default to current user
$negotiator_id = get_current_user_id();
}
echo '<p class="form-field negotiator_field">
<label for="_negotiator_id">' . __('Negotiator', 'propertyhive') . '</label>';
$args = array('name' => '_negotiator_id', 'id' => '_negotiator_id', 'class' => 'select short', 'selected' => $negotiator_id);
wp_dropdown_users($args);
echo '
</p>';
$office_id = get_post_meta($post->ID, '_office_id', TRUE);
if ($parent_post !== FALSE) {
$office_id = get_post_meta($parent_post, '_office_id', TRUE);
}
if ($office_id == '') {
// TO DO: Get primary office
}
echo '<p class="form-field negotiator_field">
<label for="_office_id">' . __('Office', 'propertyhive') . '</label>
<select id="_office_id" name="_office_id" class="select short">';
$args = array('post_type' => 'office', 'nopaging' => true, 'orderby' => 'title', 'order' => 'ASC');
$office_query = new WP_Query($args);
if ($office_query->have_posts()) {
while ($office_query->have_posts()) {
$office_query->the_post();
echo '<option value="' . $post->ID . '"';
if ($post->ID == $office_id) {
echo ' selected';
}
echo '>' . get_the_title() . '</option>';
}
}
$office_query->reset_postdata();
echo '</select>
</p>';
do_action('propertyhive_property_record_details_fields');
echo '</div>';
echo '</div>';
}
示例3: getPosts
/**
* Get posts
*
* @param array $params
*
* @return array
*/
public static function getPosts($params = array())
{
$params = is_array($params) ? $params : array();
$params['post_type'] = meAnjanWqg_Utils::arrayValueAsArray($params, 'post_type', array('post'));
$params['order'] = meAnjanWqg_Utils::arrayValueAsString($params, 'order', 'asc', 'trim');
$params['orderby'] = meAnjanWqg_Utils::arrayValueAsString($params, 'orderby', 'title', 'trim');
$params['nopaging'] = meAnjanWqg_Utils::arrayValue($params, 'nopaging', TRUE);
$params['post_parent'] = meAnjanWqg_Utils::arrayValueAsInt($params, 'post_parent', 0);
$q = new WP_Query($params);
$posts = $q->get_posts();
$q->reset_postdata();
return $posts;
}
示例4: shortcode
/**
* Blog shortcode callback
*
* @param array $atts shortcode attributes
* @param string $content shortcode content
* @param string $code shortcode name
* @return string output html
*/
public function shortcode($atts, $content = null, $code = 'blog')
{
global $woocommerce_loop;
extract(shortcode_atts(array('per_page' => '12', 'columns' => '4', 'orderby' => 'date', 'order' => 'desc'), $atts));
$args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $per_page, 'orderby' => $orderby, 'order' => $order, 'meta_query' => array(array('key' => '_visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'), array('key' => '_featured', 'value' => 'yes')));
ob_start();
$products = new WP_Query($args);
$woocommerce_loop['columns'] = $columns;
include locate_template(array('templates/woocommerce-scrollable/loop.php'));
$output = ob_get_clean();
$products->reset_postdata();
return $output;
}
示例5: array
/**
* @ticket 24785
*
*/
function test_nested_loop_reset_postdata() {
$post_id = $this->factory->post->create();
$nested_post_id = $this->factory->post->create();
$first_query = new WP_Query( array( 'post__in' => array( $post_id ) ) );
while ( $first_query->have_posts() ) { $first_query->the_post();
$second_query = new WP_Query( array( 'post__in' => array( $nested_post_id ) ) );
while ( $second_query->have_posts() ) {
$second_query->the_post();
$this->assertEquals( get_the_ID(), $nested_post_id );
}
$first_query->reset_postdata();
$this->assertEquals( get_the_ID(), $post_id );
}
}
示例6: hwml_get_all_sliders
/**
* return all hw sliders posts
* @return array
*/
function hwml_get_all_sliders()
{
if (!class_exists('HWML_Shortcodes_List')) {
return array();
}
//valid
$args = array('post_type' => HWML_Shortcodes_List::hwml_slider_posttype, 'showposts' => -1, 'orderby' => 'menu_order', 'order' => 'asc');
$result = array();
$query = new WP_Query($args);
while ($query->have_posts()) {
$query->the_post();
//$query->next_post();
$result[get_the_ID()] = get_the_title();
}
$query->reset_postdata();
//reset query
//wp_reset_postdata();
return $result;
}
示例7: get_active_conditions_settings
/**
* get active dynamic conditions setting
* @return array|mixed
*/
public static function get_active_conditions_settings()
{
$result = get_transient('hw_dynamic_conditions_settings');
if (!$result) {
$args = array('post_type' => HW_Conditions_Manager::post_type, 'showposts' => -1, 'orderby' => 'menu_order', 'order' => 'asc', 'meta_key' => 'enable', 'meta_query' => array(array('key' => 'enable', 'value' => '1')));
$result = array();
$query = new WP_Query($args);
while ($query->have_posts()) {
$query->the_post();
//$query->next_post();
$query_data_and = get_post_meta(get_the_ID(), 'query_data_and', true);
$query_data_or = get_post_meta(get_the_ID(), 'query_data_or', true);
$result[get_the_ID()] = array('title' => get_the_title(), 'query_data_and' => $query_data_and, 'query_data_or' => $query_data_or, 'post_ID' => get_the_ID());
}
$query->reset_postdata();
//reset query
set_transient('hw_dynamic_conditions_settings', $result);
//set cache fetch from database
}
return $result;
}
示例8: mediapress
function reset_gallery_data()
{
parent::reset_postdata();
if (!empty($this->post)) {
mediapress()->current_gallery = mpp_get_gallery($this->post);
}
}
示例9: while
<?php
if ($tiles->have_posts()) {
?>
<ul class="moo-tiles__container">
<?php
while ($tiles->have_posts()) {
$tiles->the_post();
$tilebg = moo_get_tilebg($post->ID);
?>
<li class="moo-tile__container" style="background-image:url('<?php
echo $tilebg;
?>
')">
<a href="<?php
the_permalink();
?>
" class="moo-tile">
<h2 class="moo-tile__title"><?php
the_title();
?>
</h2>
</a>
</li>
<?php
}
?>
</ul>
<?php
}
$tiles->reset_postdata();
示例10: reset_media_data
public function reset_media_data()
{
parent::reset_postdata();
if (!empty($this->post)) {
mediapress()->current_media = mpp_get_media($this->post);
}
}
示例11: while
<p class="lead"><?php
print_custom_field('Tagline');
?>
</p>
<div class="list"><ol>
<?php
$episodes = new WP_Query(array('post_type' => 'podcast', 'post_status' => 'publish', 'posts_per_page' => -1));
if ($episodes->have_posts()) {
while ($episodes->have_posts()) {
$episodes->the_post();
if (get_custom_field('channel') == $channel) {
$url1 = get_permalink();
echo '<li>' . "<a href={$url1}>" . get_custom_field('episode') . '</a></li>';
}
}
$my_query->reset_postdata();
}
?>
</ol>
</div>
<div class="text-center read-more"><span class="glyphicon glyphicon-chevron-down clk" /></div>
</div>
</div>
</div>
<?php
$var = $var + 1;
}
wp_reset_query();
?>
<script src="/cd/wp-content/themes/custom bootstrap theme v3/js/disturbances.js"></script>