所以我终于想出了两种方法。第一种方法是。。。
global $wp_query;
$args = array(
array(
\'numberposts\' => 3,
\'offset\' => 0,
\'orderby\' => \'post_date\',
\'order\' => \'DESC\',
\'post_type\' => \'gp_news\',
\'post_status\' => \'publish\',
\'meta_key\' => \'_thumbnail_id\',
\'meta_value\' => 1,
\'meta_compare\' => \'>=\'
),
array(
\'numberposts\' => 1,
\'offset\' => 0,
\'orderby\' => \'post_date\',
\'order\' => \'DESC\',
\'post_type\' => \'gp_competitions\',
\'post_status\' => \'publish\'
)
);
echo \'<ul class="hp_minifeatured">\';
$temp_query = clone $wp_query;
for($index = 0; $index < count($args); $index++) {
$myposts = new WP_Query( $args[$index] );
if($myposts->have_posts()) {
while($myposts->have_posts()) {
$myposts->the_post();
echo \'<li>\';
if ( has_post_thumbnail() ) {
the_post_thumbnail( \'homepage-thumbnail\' );
}
?>
<p><?php echo($args[$index][\'post_type\']); ?></p>
<h1><a href="<?php the_permalink(); ?>" title="Permalink to <?php esc_attr(the_title()); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?>">Continue...</a>
<?php
echo \'</li>\';
}
}
}
$wp_query = clone $temp_query;
echo \'</ul><div class="clear"></div>\';
。。。但这会导致使用多个查询。
另一种方法是。。。
global $wpdb;
global $post;
$querystr = "(SELECT wp_posts.* FROM $wpdb->posts wp_posts, $wpdb->postmeta wp_postmeta WHERE wp_posts.ID = wp_postmeta.post_id and wp_posts.post_status = \'publish\' and wp_posts.post_type = \'gp_news\' and wp_postmeta.meta_key = \'_thumbnail_id\' and wp_postmeta.meta_value >= 1 ORDER BY wp_posts.post_date DESC LIMIT 3) union (SELECT wp_posts.* FROM $wpdb->posts wp_posts, $wpdb->postmeta wp_postmeta WHERE wp_posts.ID = wp_postmeta.post_id and wp_posts.post_status = \'publish\' and wp_posts.post_type = \'gp_competitions\' and wp_postmeta.meta_key = \'_thumbnail_id\' and wp_postmeta.meta_value >= 1 ORDER BY wp_posts.post_date DESC LIMIT 1)";
$pageposts = $wpdb->get_results($querystr, OBJECT);
if ($pageposts) {
foreach ($pageposts as $post) {
setup_postdata($post);
echo \'<li>\';
if ( has_post_thumbnail() ) {
the_post_thumbnail( \'homepage-thumbnail\' );
}
?>
<h1><a href="<?php the_permalink(); ?>" title="Permalink to <?php esc_attr(the_title()); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?>">Continue...</a>
<?php
echo \'</li>\';
}
}