这是我要做的。这是经过轻度测试的。
它获取您需要的所有帖子的ID,然后构建一个查询,以正确的顺序获取帖子。
// get your page IDs, I assume this returns an array of integers
$page_ids = get_pageslug(" \'first_page\', \'second_page\' ");
// get your blog post ID
$blog_ids = new WP_Query( array(
\'post_type\'=> array( \'blog\' ),
\'posts_per_page\' => 1,
\'fields\' => \'ids\', // just get the ID
\'cache_results\' => false // because we\'re only getting the ID
) );
$my_wp_query_args = array(
\'post_type\' => array( \'blog\', \'page\' ),
\'post__in\' => array_merge( $page_ids, $blog_ids->posts ), // merge two arrays of IDs
\'meta_key\' => \'my_ordering\',
\'orderby\' => \'meta_value_num\', // meta_value_num is used *in place of* meta_value
\'order\' => \'ASC\'
);
// NOTE: $wp_query is an internal WP object already so don\'t overwrite it.
$my_wp_query = new WP_Query( $my_wp_query_args );
while ( $my_wp_query->have_posts() ) : $my_wp_query->the_post();
$box_ordering = get_post_meta($post->ID, \'my_ordering\', true);
echo $box_ordering . \'<br>\'; //outputs meta values for each page/post correctly
endwhile;