【发布时间】:2021-05-13 13:03:34
【问题描述】:
我有一个会话数组 ($_SESSION['recently_viewed']),它当前输出以下内容:
array(3) { [0]=> int(635) [1]=> int(643) [2]=> int(474) }
635、643 和 474 是我的自定义帖子类型中的 IDs,称为 accessories。
我正在尝试显示属于该数组的帖子,但不确定如何在逻辑上执行此操作。
到目前为止我有:
<?php
global $post;
$args = array(
'post_type' => 'accessories',
'p' => $_SESSION['recently_viewed'], // something like this, but logically correct
'post_status' => 'publish',
);
$query = new WP_Query( $args );
if($query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
echo the_title();
endwhile; wp_reset_postdata(); ?>
<?php endif; ?>
我该怎么做?
【问题讨论】: