我使用以下查询从两种不同类型中提取帖子。但是,如何在实际的内容显示条件代码中针对它们?
if($my\\u query->post\\u type==“featured”)不起作用。我还尝试了if(post\\u type==“featured”)。
<?php
// query posts
$my_query = new WP_Query
( array(
\'post_status\' => \'publish\',
\'post_type\' => array(\'featured\', \'wpsc-product\'),
\'orderby\' => \'menu_order\',
\'order\' => \'ASC\',
\'showposts\' => 50 ));
while( $my_query->have_posts() ) : $my_query->the_post();
$fitemlink = get_post_meta($post->ID,\'new_fitemlink\',true);
// display the content
if ($my_query->post_type == \'featured\' ) {
echo get_image_path(get_post_meta($post->ID, \'slideimage_src\', true));
} else if ($my_query->post_type == \'wpsc-product\' ) {
echo wpsc_the_product_image(); }
endwhile; ?>
最合适的回答,由SO网友:SolaceBeforeDawn 整理而成
我最终通过一个简单的查询解决了这个问题
if ( \'featured\' == get_post_type() ) { echo get_image_path(get_post_meta($post->ID, \'snbf_slideimage_src\', true)); } else if ( \'wpsc-product\' == get_post_type() ) { echo wpsc_the_product_image();