/indexer/index_object
This filter is called before a facet object (post, term or user) is indexed.
It allows to bypass the default index system by returning a custom array holding at least one row (to insert in the index table) with a facet_value
and facet_name
. If an empty value is set to the facet_value
, row will not be indexed.
facet_value
is used to match posts/terms/users when filtering.facet_name
is displayed as a label in a facet.
Argument | Type | Description |
$rows | array | Holds index rows of the current object id (empty by default) |
$object_id | integer | Post, term or user id to index |
$facet | array | Holds facet settings |
[pastacode lang=”php” manual=”function%20prefix_index_object(%20%24rows%2C%20%24object_id%2C%20%24facet%20)%20%7B%5C%0A%0A%09%2F%2F%20We%20skip%20facet%20IDs%20different%20from%201.%20%0A%09if%20(%201%20!%3D%3D%20%24facet%5B’id’%5D%20)%20%7B%0A%09%09return%20%24rows%3B%0A%09%7D%0A%0A%09%24start_date%20%3D%20get_post_meta(%20%24object_id%2C%20’start_date’%2C%20true%20)%3B%0A%09%0A%09if%20(%20empty(%20%24start_date%20)%20)%20%7B%0A%09return%20%24rows%3B%0A%09%7D%0A%0A%09%2F%2F%20It%20may%20contains%20several%20rows%20(nested%20arrays).%0A%09%2F%2F%20Return%20rows%20to%20insert%20in%20the%20index%20table.%20%0A%0A%09return%20%5B%20%0A%09%09%5B%20’facet_value’%20%3D%3E%20date(%20’Y-m-d’%2C%20strtotime(%20%24start_date%20)%20)%2C%0A%09%09’facet_name’%20%3D%3E%20’Start%20date’%2C%0A%09%09%5D%2C%0A%09%5D%3B%0A%7D%0A%0Aadd_filter(%20’wp_grid_builder%2Findexer%2Findex_object’%2C%20’prefix_index_object’%2C%2010%2C%203%20)%3B” message=”” highlight=”” provider=”manual”/]