0
我正在運行一個自定義查詢,但是當返回posts_per_page時,它總是落在後面。我正在使用一種稱爲事件的自定義帖子類型,即拉動代碼以顯示函數文件中的帖子。我也想實現分頁(也不工作),這會是一個問題嗎?WordPress的自定義查詢丟失了兩篇文章
我已經跑了var dump,它返回查詢中的所有內容,包括當前日期之前的帖子。我想象因爲它在if語句之前傾倒了嗎?有任何想法嗎?
任何想法?
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
//Current exhibitions
$args = array(
'post_type' => 'exhibitions',
'orderby' => 'exhibition_start_date',
'meta_key' => 'exhibition_start_date',
'order' => 'ASC',
'posts_per_page' => 6,
'paged' => $paged
);
$my_query = new WP_Query($args);
while ($my_query->have_posts()) : $my_query->the_post();
$exhibition_start_date = get_post_meta($post->ID, 'exhibition_start_date', true);
//Current
if ($exhibition_start_date >= date('Y-m-d')) {
get_exhibition_container();
}
endwhile;
wp_reset_postdata();
?>
新的代碼:(?我還添加了在我最初的循環帶來的頁面內容,認爲它可能interfear)
<div role="main" class="clearfix">
<div class="one-column">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endwhile; else: ?>
<?php endif; ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
//Current exhibitions
$args = array(
'post_type' => 'exhibitions',
'meta_query' => array(
array (
'key' => 'exhibition_start_date',
'value' => date('Y-m-d'),
'compare' => '>='
)
),
'orderby' => 'exhibition_start_date',
'meta_key' => 'exhibition_start_date',
'order' => 'ASC',
'posts_per_page' => 10,
'paged' => $paged
);
$my_query = new WP_Query($args);
while ($my_query->have_posts()) : $my_query->the_post();
$exhibition_start_date = get_post_meta($post->ID, 'exhibition_start_date', true);
//Current
get_exhibition_container();
endwhile;
wp_reset_postdata();
?>
<div class="previous-holder">
<?php previous_posts_link(); ?>
</div>
<div class="next-holder">
<?php next_posts_link(); ?>
</div>
之前,唯一的問題是,現在仍然分頁不工作? – Amy
代碼中的分頁鏈接在哪裏? – soju
在循環的底部,我需要在內部引用它們嗎? – Amy