Support Forum
Support › MB Custom Table › FacetWP & Custom Tables
Tran, hi!
Does the FacetWP Integrator work with custom fields that are stored in a custom table?
Thanks, James
Hi James,
Unfortunately, no. The FacetWP plugin doesn't handle data stored in a custom table 🙁
What would I have to do to customize the FacetWP Integrator so that it would loop through the custom fields that I want to use as facets or indices? Is there not a way to have the Integrator do this by using the parameters ‘storage_type’ & ‘my_table_name’?
I don't know if this is helpful.
"When the “Re-index” button is clicked, FacetWP first retrieves all post IDs that should be indexed. It uses WP_Query, and the query arguments are customizable.
FacetWP then loops through the array of post IDs. For each, it loops through all available facets and saves applicable values."
https://facetwp.com/how-facetwps-indexer-works/
https://facetwp.com/documentation/facetwp_indexer_query_args/
Hi James,
Great stuffs!
What would I have to do to customize the FacetWP Integrator so that it would loop through the custom fields that I want to use as facets or indices? Is there not a way to have the Integrator do this by using the parameters ‘storage_type’ & ‘my_table_name’?
I forgot about this! The Integrator uses Meta Box's function rwmb_get_value()
to get field value and that already handles the storage type. Theoretically, it should work! Can you please just try it and let me know how it goes?
Anh Tran, thanks for the quick response and all the great information. I’ll definitely try it out & let you know. If you don’t mind, could you please satisfy my curiosity and tell me how/where rwmb_get_value() “handles the storage type”? What I mean is: where is ‘storage type’ & ‘table name’ for each custom field stored in the WP db? (I realize that a custom field will not have these attributes if the custom field uses the postmeta table.) I apologize for all the questions, I’m just trying to understand how/where custom fields & metaboxes & custom field groups are “registered” and where their attributes are stored. (I’ve researched this quite a bit and have not found the answers. I hope my questions make sense.)
Thanks much, James
No problem.
Here is the process of creating the storage for meta box and its fields:
- When a meta box is created, a storage will be created for it. The function rwmb_get_storage()
will handle the creation.
- The rwmb_get_storage()
uses a filter rwmb_get_storage
that allow extensions to change the storage. That's where the MB Custom Table filters and change the storage to work with post meta to the one works with the custom table. In this filter, the whole meta box settings is passed, so extensions know the storage_type
and table name.
- After the creation, this storage will be added to all fields in the meta box via $field['storage']
parameter.
- When working with the meta value (get/save), this storage will be use like $field['storage']->get()
and $field['storage']->update()
.
So, storage is kind of the abstract layer between the code and the database. And that can be changed with filters.
That's how the plugins work. If there's something unclear, please let me know.
I'm replying here to receive email updates and follow the conversation. No need for other response.
Thanks!
jcleaveland, welcome to the conversation.
Anh, thank you for the detailed explanation of rwnb_get_storage(). I think I understand, except I don't understand an earlier thread (3/7/18) between you & jcleaveland where I believe you recommended creating a custom storage. I couldn't understand that conversation well enough to understand when someone would need to create a custom storage.
Hi, which topic are you talking about? I'm happy to clarify if there's something unclear.
Anh, hi!
This is the thread I'm talking about when I said "I couldn’t understand that conversation well enough to understand when someone would need to create a custom storage":
https://support.metabox.io/topic/custom-db-table-integration/
I realize my question is rather open-ended; so if this is too broad a topic for you to explain, I understand.
Thanks,
James
Ah, I see.
The storage is an abstract layer between the data and custom fields. With the implementation in the Meta Box plugin, we can create a custom storage to decide where to save data. As you can see, we have implemented storages for post/term/user/comment meta, settings pages (option) and custom table.
In that thread, @Jackky wants to create a custom storage for a custom table, which has a different structure than the one provided by the MB Custom Table extension. That's why I instructed him to create a custom storage for his custom table.
Hope that make things clearer 🙂
I get it know.
Thanks