我认为这个问题在互联网上很容易找到……然而,似乎以前没有人遇到过这个问题。
输入搜索词时,列出搜索查询没有问题,I needed posts and pages to be differentiated in a way. 例如:我希望作为帖子(文章)的结果显示作者、阅读时间和发布日期,但我不希望这些元显示在作为页面的结果上。
以下是代码:
$paged = ( get_query_var( \'paged\' ) ) ? get_query_var( \'paged\' ) : 1;
$searchArgs = array(
\'s\' => $s,
\'paged\' => $paged,
\'showposts\' => -1,
);
$searchQuery = new WP_Query( $searchArgs );
if ( $searchQuery->have_posts() ) :
echo \'<h2>\';
echo \'result: \'.search_query();
echo \'</h2>\';
while ( $searchQuery->have_posts() ) : $searchQuery->the_post();
echo \'link: \'.get_the_permalink();
echo \'Title: \'.get_the_title();
echo \'Post Summary: \'.get_the_excerpt();
$how = ( is_single() ) ? \'this result is a post\' : \'your method did not work\'; //always return false
$how = ( is_page() ) ? \'this result is a page\' : \'your method did not work\'; //always return false.
echo \'Post Type: \'.$how; // <------ How to do?
//***Problem***: is_single() or is_page() does not work, by the way (both return false).
//I\'ve crossed-checked that the results are actually either a post or a page.
endwhile;
endif;
if ( function_exists(\'custom_pagination\') ) {
custom_pagination($searchQuery->max_num_pages,"",$paged);
}
所以我的问题是,is\\u page()和is\\u single()在我所做的搜索查询中不起作用。你如何正确地做到这一点?