{"id":4897,"date":"2020-06-03T14:02:55","date_gmt":"2020-06-03T14:02:55","guid":{"rendered":"https:\/\/the7kennisbank.nl\/?p=4897"},"modified":"2020-06-09T13:22:22","modified_gmt":"2020-06-09T13:22:22","slug":"filter-indexer-index-object","status":"publish","type":"post","link":"https:\/\/the7kennisbank.nl\/en\/wp-grid-builder\/filter-indexer-index-object\/","title":{"rendered":"Filter indexer index object"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element \" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<div>\n<div class=\"container flex items-center justify-between\">\n<h1 class=\"entry-title\">\/indexer\/index_object<\/h1>\n<\/div>\n<\/div>\n<div id=\"article-wrapper\" class=\"container\">\n<p>This filter is called before a facet object (post, term or user) is indexed.<\/p>\n<p>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 <code>facet_value<\/code> and <code>facet_name<\/code>. If an empty value is set to the <code>facet_value<\/code> , row will not be indexed.<\/p>\n<ul>\n<li><code>facet_value<\/code> is used to match posts\/terms\/users when filtering.<\/li>\n<li><code>facet_name<\/code> is displayed as a label in a facet.<\/li>\n<\/ul>\n<table class=\"wp-block-table arguments-table\">\n<tbody>\n<tr>\n<td>Argument<\/td>\n<td>Type<\/td>\n<td>Description<\/td>\n<\/tr>\n<tr>\n<td>$rows<\/td>\n<td>array<\/td>\n<td>Holds index rows of the current object id (empty by default)<\/td>\n<\/tr>\n<tr>\n<td>$object_id<\/td>\n<td>integer<\/td>\n<td>Post, term or user id to index<\/td>\n<\/tr>\n<tr>\n<td>$facet<\/td>\n<td>array<\/td>\n<td>Holds facet settings<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"code-syntax-block code-syntax-wrapper\">\n<p>[pastacode lang=&#8221;php&#8221; manual=&#8221;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&#8217;id&#8217;%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&#8217;start_date&#8217;%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&#8217;facet_value&#8217;%20%3D%3E%20date(%20&#8217;Y-m-d&#8217;%2C%20strtotime(%20%24start_date%20)%20)%2C%0A%09%09&#8217;facet_name&#8217;%20%3D%3E%20&#8217;Start%20date&#8217;%2C%0A%09%09%5D%2C%0A%09%5D%3B%0A%7D%0A%0Aadd_filter(%20&#8217;wp_grid_builder%2Findexer%2Findex_object&#8217;%2C%20&#8217;prefix_index_object&#8217;%2C%2010%2C%203%20)%3B&#8221; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;\/]<\/p>\n<\/div>\n<\/div>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>\/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&hellip;<\/p>\n","protected":false},"author":2,"featured_media":4996,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[44,57,43],"tags":[],"class_list":["post-4897","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-documentation","category-php-filters","category-wp-grid-builder","category-44","category-57","category-43","description-off"],"acf":[],"_links":{"self":[{"href":"https:\/\/the7kennisbank.nl\/en\/wp-json\/wp\/v2\/posts\/4897","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/the7kennisbank.nl\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/the7kennisbank.nl\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/the7kennisbank.nl\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/the7kennisbank.nl\/en\/wp-json\/wp\/v2\/comments?post=4897"}],"version-history":[{"count":3,"href":"https:\/\/the7kennisbank.nl\/en\/wp-json\/wp\/v2\/posts\/4897\/revisions"}],"predecessor-version":[{"id":5102,"href":"https:\/\/the7kennisbank.nl\/en\/wp-json\/wp\/v2\/posts\/4897\/revisions\/5102"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/the7kennisbank.nl\/en\/wp-json\/wp\/v2\/media\/4996"}],"wp:attachment":[{"href":"https:\/\/the7kennisbank.nl\/en\/wp-json\/wp\/v2\/media?parent=4897"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/the7kennisbank.nl\/en\/wp-json\/wp\/v2\/categories?post=4897"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/the7kennisbank.nl\/en\/wp-json\/wp\/v2\/tags?post=4897"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}