Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algolia Wordpress将搜索限制为仅发布标题_Wordpress_Algolia - Fatal编程技术网

Algolia Wordpress将搜索限制为仅发布标题

Algolia Wordpress将搜索限制为仅发布标题,wordpress,algolia,Wordpress,Algolia,有没有办法将搜索限制为只在Wordpress上发布带有Algolia的标题 我需要这个自动完成功能 您完全可以自定义搜索所基于的字段 首先,您必须让Algolia知道,您只想通过更改attributesToIndex设置来搜索帖子标题字段: /** * @param array $settings * * @return array */ function custom_posts_index_settings( array $settings ) { $settings['at

有没有办法将搜索限制为只在Wordpress上发布带有Algolia的标题


我需要这个自动完成功能

您完全可以自定义搜索所基于的字段

首先,您必须让Algolia知道,您只想通过更改
attributesToIndex
设置来搜索帖子标题字段:

/**
 * @param array $settings
 *
 * @return array
 */
function custom_posts_index_settings( array $settings ) {
    $settings['attributesToIndex'] = array( 'unordered(post_title)' );

    return $settings;
}

add_filter('algolia_posts_index_settings', 'custom_posts_index_settings');
add_filter('algolia_searchable_posts_index_settings', 'custom_posts_index_settings');
然后,您需要通过首先将autocomplete.php文件移动到主题文件夹来定制autocomplete的建议模板,如本指南中所述:

基本上,您将移除看起来像这样的零件:

<#
            var attributes = ['content', 'title6', 'title5', 'title4', 'title3', 'title2', 'title1'];
            var attribute_name;
            var relevant_content = '';
            for ( var index in attributes ) {
            attribute_name = attributes[ index ];
            if ( data._highlightResult[ attribute_name ].matchedWords.length > 0 ) {
            relevant_content = data._snippetResult[ attribute_name ].value;
            break;
            } else if( data._snippetResult[ attribute_name ].value !== '' ) {
            relevant_content = data._snippetResult[ attribute_name ].value;
            }
            }
            #>
0){
相关内容=数据。\结果[属性\名称].值;
打破
}else if(数据.\u代码段结果[属性\u名称].值!=''){
相关内容=数据。\结果[属性\名称].值;
}
}
#>

如果删除整个部分,则不会得到自动完成结果。。你的意思是我只需要删除“content”属性吗?你介意共享一个活动实例以便我们看到最终的错误吗?