有没有办法包括page images 在wp搜索中?就像我想搜索我的网站images on pages not in posts 按标题/alt文本,并在结果页中显示为缩略图。
在默认的wp搜索中包括来自wp earch.php结果中页面的图像
1 个回复
最合适的回答,由SO网友:Junaid 整理而成
包括attachment
(媒体)在搜索结果中发布类型,请使用以下代码段
function attachment_search( $query ) {
if ( $query->is_search ) {
$query->set( \'post_type\', array( \'post\', \'attachment\' ) );
$query->set( \'post_status\', array( \'publish\', \'inherit\' ) );
}
return $query;
}
add_filter( \'pre_get_posts\', \'attachment_search\' );
然而,这并不关心搜索结果的显示方式,但这是另一个线程的讨论。这应该是可行的,但如果您想添加页面,请替换
$query->set( \'post_type\', array( \'post\', \'attachment\' ) );
使用$query->set( \'post_type\', array( \'post\', \'page\', \'attachment\' ) );
结束