1

I have a basic query that displays latest news, but I added a custom field in the post editor so the user can define the Post ID's of the specific latest news they want to display.

$relatedpostnums = get_post_meta($post->ID, 'relatedpostnums', true);
$query = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 5, 'post__in' => array( 31,7,53,35 ) ) ); while($query->have_posts()) : $query->the_post();

I have 31,7,53,35 as the posts I want to display. that is manually entered. If I want it to be dynamic, how do I replace those 4 numbers with the output from $relatedpostnums?

I did this (replaced the 4 numbers with $relatedpostnums):

$relatedpostnums = get_post_meta($post->ID, 'relatedpostnums', true);
$query = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 5, 'post__in' => array( $relatedpostnums ) ) ); while($query->have_posts()) : $query->the_post();

But it only displays the first number, even if I set it to posts_per_page to 4

4

1 回答 1

0

第三个参数get_post_meta == true表示该函数将返回单个结果,作为字符串(您的最新 ID)。

使其为假或不将返回一个数组

请参阅此参考

于 2013-07-31T00:15:33.080 回答