我有以下wordpress循环,并且它永远需要将页面粘贴在火狐的圆圈上并且想知道是否有人新的如何加速这个页面模板我只是使用高级Cusotm字段不应该采取这个很久以来。
是否有任何突出的人会导致渲染页面需要很长时间。我也得到了这个脚本的内存分配问题,任何帮助都是非常有用的。
<?php
/**
* Template Name: Well Being Page Template
*
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
?>
<?php get_header(); ?>
<?php
$ip = getenv('HTTP_CLIENT_IP')?:
getenv('HTTP_X_FORWARDED_FOR')?:
getenv('HTTP_X_FORWARDED')?:
getenv('HTTP_FORWARDED_FOR')?:
getenv('HTTP_FORWARDED')?:
getenv('REMOTE_ADDR');
// args
$args = array(
'numberposts' => -1,
'post_type' => 'wellbeing',
'post_status' => 'publish',
'meta_key' => 'ip',
'meta_value' => $ip
);
// query
$the_query = new WP_Query( $args );
$isFound=false;
?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : ?>
<?php $isFound=true;?>
<?php endwhile; else: ?>
<?php $isFound=false;?>
<p><?php
_e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<?php
if($isFound==true )
{
}else
{
// Gather post data.
$my_post = array(
'post_title' => 'Opt In',
'post_content' => 'This is my post.',
'post_type' => 'wellbeing',
'meta_key' => 'ip',
'meta_value' => $ip,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array( 8,39 )
);
// Insert the post into the database.
$post_id = wp_insert_post( $my_post );
$date = new DateTime();
$date->modify('+2 week');
$currentdate = date('m/d/Y h:i:s', time());
// save a basic text value
$field_key = "expirey_date";
$twoweeksaway = $date->format('m/d/Y h:i:s');;
update_field( $field_key, $value, $post_id );
// save a basic text value
$field_key = "date_joined";
$value = $currentdate;
update_field( $field_key, $value, $post_id );
$current_user = wp_get_current_user();
// save a basic text value
$field_key = "ip";
$value = $ip;
update_field( $field_key, $value, $post_id );
// save a basic text value
$field_key = "email";
$value = wpse_email();
update_field( $field_key, $value, $post_id );
};
?>
<?php
$dateJoined=the_field('date_joined', $post_id );
$expiredate=the_field('expirey_date', $post_id );
?>
<?php
//we want to disable the option to opt out of well being
if($dateJoined >= $expiredate) { ?>
<div style="clear:both;">
Welcome this page allows you to opt out of our well being program. You have <?php $daysleft =currentdate -twoweeksaway; echo $daysleft;?>
Do you wish to opt out of the well being program
</div>
<div class="form-group">
<form name="wellbeing" action="<?php echo get_permalink(); ?>" method="post">
<input type="submit" value="Submit">
</div>
</form><?php }; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
<?php get_footer(); ?>
答案 0 :(得分:0)
我建议你像这样制作你的循环:
$isFound = false;
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) :
$the_query->the_post();
$isFound=true;
endwhile;
wp_reset_postdata();
enfif;
如果没有the_post()
则不起作用,您必须wp_reset_postdata()
才能影响页面的其余部分。