我正在使用带有ajax搜索功能的wp主题来获取实时建议。然而,suggestion元素显示帖子类型(在结果标题下),例如“投资组合项目”,我想用帖子(投资组合项目)类别替换它。有解决方案吗提前谢谢!
$suggestions=array();
global $post;
foreach ($posts as $post): setup_postdata($post);
// Initialise suggestion array
$suggestion = array();
$suggestion['label'] = esc_html($post->post_title);
$suggestion['link'] = get_permalink();
$suggestion['image'] = (has_post_thumbnail( $post->ID )) ? get_the_post_thumbnail($post->ID, 'thumbnail', array('title' => '')) : '<i class="icon-salient-pencil"></i>' ;
if(get_post_type($post->ID) == 'post'){
$suggestion['post_type'] = __('Story',NECTAR_THEME_NAME);
} else if(get_post_type($post->ID) == 'page'){
$suggestion['post_type'] = __('Page',NECTAR_THEME_NAME);
} else if(get_post_type($post->ID) == 'portfolio'){
$suggestion['post_type'] = __('Portfolio item',NECTAR_THEME_NAME);
//show custom thumbnail if in use
$custom_thumbnail = get_post_meta($post->ID, '_nectar_portfolio_custom_thumbnail', true);
if(!empty($custom_thumbnail) ){
$attachment_id = pn_get_attachment_id_from_url($custom_thumbnail);
$suggestion['image'] = wp_get_attachment_image($attachment_id,'portfolio-widget');
}
} else if(get_post_type($post->ID) == 'product'){
$suggestion['post_type'] = __('Product',NECTAR_THEME_NAME);
}