php facetwp索引仅指导父项的子项

Posted

tags:

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

<?php
/**
 ** filter on facetwp_index_row to index only direct children of a parent term
 ** this is for use with Parent term setting which by default indexes child terms, and grand child terms, etc
 ** If you want to have the index include posts of child/grandchild, etc of terms, you need to set Hierarchical to yes
 **/

add_filter( 'facetwp_index_row', function( $params, $class ) {
	if ( in_array( $params['facet_name'], array( 'my_facet', 'my_other_facet' ) ) ) { // create an array of facet names to check against
	    $parent = $class->facet['parent_term']; // this gives the parent term from the facet's settings
	    if ( $parent != $params['parent_id'] ) { // $params['parent_id'] is the parent id of the term being indexed
	        return false;
        }
	}
	return $params;
}, 10, 2 );

以上是关于php facetwp索引仅指导父项的子项的主要内容,如果未能解决你的问题,请参考以下文章

如何将父项的第一个子项中的属性移动到 XSLT 中的父项?

将子项和父项的平展列表到树视图层次结构

如何查找非间接/嵌套父项的子项

php facetwp索引仅限父级和一级子级条款

php facetwp索引仅限父级和一级子级条款

如何在php中数组的父项下显示子项