【发布时间】:2016-08-27 05:34:00
【问题描述】:
我是 wordpress 新手,我正在尝试为多种自定义帖子类型创建存档页面。
我有两种自定义帖子类型,“公平”和“展览” 我目前有两个存档页面,带有 pre get post 操作:
add_action( 'pre_get_posts', function ( $q )
{
if ( !is_admin() // VERY important, targets only front end queries
&& $q->is_main_query() // VERY important, targets only main query
&& $q->is_post_type_archive( 'fair' ) // Which post type archive page to target
) {
$q->set( 'oderby', 'meta_value_num' );
$q->set( 'meta_key', '_datepicker');
$q->set('showposts', 3);
$q->set('is_post_type_archive', false);
$q->set('order', 'ASC');
// Rest of your arguments to set
}
});
两种自定义帖子类型都有相同的元框,我想在存档页面“公平”上显示这两种帖子类型,或者在必要时显示新的帖子类型
我尝试添加
$q->set('post_type', array('fair', 'exhibition'));
到函数。
当我这样做时,我有我的两种帖子类型,但我的自定义存档页面(“archive-fair.php”)似乎没有被调用
如何使用功能分页正确执行两种帖子类型的存档页面?
感谢和抱歉我的英语,我希望它是可以理解的。
编辑:我的 archive-post.php 页面看起来像:
<?php get_header();
while ( have_posts() )
{
the_post();
$p_type = get_post_type(get_the_ID());
if ($p_type == 'fair')
$img = get_post_meta(get_the_ID(), "wp_fair_attachment", true);
else
$img = get_post_meta(get_the_ID(), "wp_exhibition_attachment", true);
?>
some html
<?php } ?>
【问题讨论】:
标签: php wordpress custom-post-type archive