我正在创建一个“循环”,它需要按照ID的定义顺序显示页面(而不是帖子)。到目前为止,我所做的是:
<?php
$ids = array(434, 814, 3660, 3235, 99, 1002, etc.);
add_filter(\'posts_orderby\', \'enforce_specific_order\');
function enforce_specific_order($orderby) {
global $wpdb;
$ids_as_text = join(",",$ids);
return "FIND_IN_SET(".$wpdb->posts.".ID, \'".$ids_as_text."\') ASC";
}
global $post;
$args = array( \'posts_per_page\' => 20, \'post_type\' => \'page\', \'post__in\' => $ids );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<h2><?php the_title(); ?></h2>
<?php endforeach; remove_filter( current_filter(), __FUNCTION__ ); wp_reset_postdata(); ?>
我可以看到页面标题正确显示,但没有按照我期望的顺序显示
$ids
.
有什么想法吗?