php facetwp facetwp_facet_filter_posts钩子

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php facetwp facetwp_facet_filter_posts钩子相关的知识,希望对你有一定的参考价值。

<?php

/** filter to return post_ids from a multi-select, narrow results facet **/
add_filter( 'facetwp_facet_filter_posts', function( $return, $params ) {

	if ( 'product_categories' == $params['facet']['name'] ) {
	    
		global $wpdb;

		$return          = array();
		$facet           = $params['facet'];
		$selected_values = $params['selected_values'];

		$sql = $wpdb->prepare( "SELECT DISTINCT post_id
            FROM {$wpdb->prefix}facetwp_index
            WHERE facet_name = %s",
			$facet['name']
		);

		// Match ALL values
		foreach ( $selected_values as $key => $value ) {
			$results = facetwp_sql( $sql . " AND facet_value IN ('$value')", $facet );
			$return  = ( $key > 0 ) ? array_intersect( $return, $results ) : $results;

			if ( empty( $return ) ) {
				break;
			}
		}

	}

	return $return;
}, 10, 2 );

以上是关于php facetwp facetwp_facet_filter_posts钩子的主要内容,如果未能解决你的问题,请参考以下文章

php facetwp在GeneratePress中显示facetwp寻呼机

php facetwp添加facetwp-template下载短代码

php facetwp添加facetwp-template下载短代码

php facetwp在facetwp模板中使用woocommerce占位符图像

php facetwp facetwp_facet_filter_posts钩子

php facetwp facetwp_wpdb_sql过滤器