Wordpress WP_GeoQuery를 실행하여 아무런 문제없이 위치에 따라 맞춤 게시물 유형 내의 게시물을 가져옵니다. 그러나 루프는 사이드 바의 & 바닥 글을 포함하여 페이지의 나머지 HTML을 손상시킵니다. 나는 'posts_per_page'옵션으로 놀았고, Wordpress가 61 번째 (난수가 아는) 게시물 이후에 죽는 것처럼 보입니다.Wordpress 루프가 61 번째 게시물 이후에 HTML을 축소합니다.
문제를 해결할 수있는 페이지 매김을 할 수 있으며이를 수행 할 것이라고 알고 있습니다. 그러나 호기심이 내게 더 좋으며 나에게 왜 그런지 알지 못합니다. Google에서 검색했지만 답변을 찾을 수 없습니다.
그래서 기본적으로 Wordpress에 61 개의 게시물이 어딘가에 설정되어 있는지 또는 내가 어리석은 일을하고 있다면 어떨까요? 아래 코드 ...
사전에 도움을 주셔서 감사합니다!
<?php // get location of user
$url = "http://freegeoip.net/json/". $_SERVER['REMOTE_ADDR'] .'';
$geo = json_decode(file_get_contents($url), true);
// store lat and long of user location
$Slat = $geo[latitude];
$Slng = $geo[longitude];
?>
<?php $args = array(
'post_type' => 'event',
'latitude' => $Slat,
'longitude' => $Slng,
'author'=> $user_id,
'posts_per_page' => 61
)
?>
<?php $the_query = new WP_GeoQuery($args); ?>
<?php $plus = 0; ?>
<?php foreach($the_query->posts as $post) : ?>
<?php $postid = get_the_ID(); ?>
<div class="event clearfix">
<div class="event-image grid-1-4 no-padding">
<?php $images = get_field('images'); ?>
<img src="<?php echo $images[0][sizes][thumbnail]; ?>" alt="<?php the_title(); ?>" />
</div>
<div class="event-info grid-1-2">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<form action="/edit-event" method="POST">
<input type="hidden" value="<?php echo $postid; ?>" name="id" />
<input type="submit" class="edit-button" value="edit event" />
</form>
</div>
<div class="event-details grid-1-4 no-padding">
<div class="detail">Distance <?php echo round($post->distance, 1); ?> mi</div>
<div class="detail">Price: £<?php the_field('adult'); ?></div>
<?php include('countdown.php'); ?>
</div>
</div>
<?php $plus++; ?>
<?php endforeach; ?>
로그가 간과 한 경우가 있습니다. 일부 게시물에는 get_field ('images')가 포함되지 않아서 죽게되었습니다. 간단한 if 문을 사용하면 트릭을 만들 수 있습니다. 미스터리 61 번째 결함이 없습니다. 도움 주셔서 대단히 감사합니다! – holloway