php facetwp索引自动完成方面的多个值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php facetwp索引自动完成方面的多个值相关的知识,希望对你有一定的参考价值。

<?php

/**
 * add additional fields to an autocomplete factet index
 * the datasource for the autocomplete facet is set to post title
 * additional custom fields are looked up and inserted during indexing
 */
add_filter( 'facetwp_index_row', function( $params, $class ) {

	if ( 'car_search' == $params['facet_name'] ) { // make sure to change 'car_search' to the name of your facet

		$post_id = $params['post_id']; // get the currrent post id

		// copy the params to a new variable so the original is preserved
		$new_params = $params;

		// add row for make
		/** the custom fields for the cars demo are created with Custom Field Suite
		 ** you can grab any value you need from the $post_id
		 ** ex for a custom field - get_post_meta( $post_id, 'my_custom_field', true );
		 ** ex for ACF - get_field( 'my_custom_field', $post_id );
		 **/
		$value = CFS()->get( 'make', $post_id );
		$new_params['facet_value'] = sanitize_title( $value ); // this is the value for the option
		$new_params['facet_display_value'] = $value; // this is the keyword(s) that will be search on
		$class->insert( $new_params ); // adds the new row to facetwp's index

		// add row for vehicle_type
		$value = CFS()->get( 'vehicle_type', $post_id );
		$new_params['facet_value'] = sanitize_title( $value );
		$new_params['facet_display_value'] = $value;
		$class->insert( $new_params );

		// add row for driven_wheels
		$value = CFS()->get( 'driven_wheels', $post_id );
		$new_params['facet_value'] = sanitize_title( $value );
		$new_params['facet_display_value'] = $value;
		$class->insert( $new_params );

		/** return false; // uncomment if you don't want to index the original datasource **/

	}
	return $params;
}, 10, 2 );

以上是关于php facetwp索引自动完成方面的多个值的主要内容,如果未能解决你的问题,请参考以下文章

php facetwp索引新媒体

php facetwp索引一个PODS关系字段

php facetwp索引关系

php facetwp索引日期

php facetwp索引类及其子类

php facetwp索引只有父母