This add-on allows additional storage options for Relationship fields. When you have a table-based Pod, you can finally choose to store your relationships within the table itself and bypass the wp_podsrel relationship table or meta-based storage entirely. This works for storage as well as it’s completely compatible with normal Pods::find() traversal syntax.
Please note: When using this add-on and turning on/off different storage options, you will encounter points in which your data is no longer in sync with where it will be queried from and saved to. To address this, a helpful WP-CLI migration command has been created and is documented below.
Requirements
Requires WordPress 5.5+, Pods 2.8.16+, and PHP 5.6+
What does this add-on do?
Store relationships in their own table column for table-based Pods
This will store related IDs in their own column with a MySQL INDEX added to the table for the Pod. If you choose this option, related IDs will still be stored in the wp_podsrel
indexing table unless you have both Single AND Multiple Select Relationships table storage enabled. If both are enabled, you can disable the wp_podsrel
indexing table entirely in a separate option.
Control the wp_podsrel
indexing table
This will enable/disable storing relationships in the wp_podsrel
indexing table. Turning this off does not remove the wp_podsrel
table itself, it will only prevent querying relationships from it and will not store them there going forward. Please be aware that any change to this option will immediately cause future relationship data to be out of sync with anything already stored in wp_podsrel
. If you choose to turn this option on again, wp_podsrel
will take data priority and will likely be out of sync with changes made since it was off. If you turn the option on and the wp_podsrel
table does not exist, it will be automatically created.
Control meta-based storage
This will enable storing relationships in the meta table (ex. wp_postmeta
) for the associated Pod. Turning this off does not remove the existing relationship meta stored there, it will only prevent querying relationships from meta and will not store them there going forward. Please be aware that any change to this option will immediately cause future relationship data to be out of sync with anything already stored in the meta table. If you choose to turn this option on again, the meta table may take data priority and will likely be out of sync with changes made since it was off.
Customize per relationship field
You can choose to enable/disable table or meta storage per field depending on your needs, or set them on the global level through the Pods Admin > Settings page.
Migrate your relationship data using WP-CLI
With WP-CLI, you can run the built-in command to migrate relationship data from one storage type to another. This helps sync data where you want it and also can remove data once you are done.
Command
wp pods-pro-advanced-relationship-storage migrate
Arguments
--pod="my_pod"
: The pod name[--fields="my_rel_field"]
: (optional) The field names separated by comma, do not set if you want to migrate all relationship fields in pod--from="meta"
: The storage type to migrate from (meta, podsrel, table)--to="table"
: The storage type(s) to migrate to (meta, podsrel, table) separated by comma[--delete-from="meta"]
: (optional) Whether to delete relationship data from other storage types separated by comma after migrating[--per-page="1000"]
: (optional) The number of rows to process per page of the migration, defaults to 1000[--clean-memory-after="100"]
: (optional) The number of rows to process before cleaning up memory, defaults to 100. This option helps prevent large processes from being killed when they run out of memory.[--force-save-field-setting]
: (optional) By default, running the migration will enable table-based storage when theto
argument is table. If you’d like to also save the setting as off (when migrating away from table-based) then use this argument[--no-save-field-setting]
: (optional) By default, running the migration will enable table-based storage when theto
argument is table. If you’d like to not save the table-based field setting for your fields, you can disable that with this argument[--save-field-setting-only]
: (optional) You can choose to only save the field setting and not migrate any relationship data by using this argument[--test]
: (optional) Whether to run the migration in test mode and not change/remove any data in the database
Example: Migrate the field “my_rel_field” on the “my_pod” pod from meta to table storage
wp pods-pro-advanced-relationship-storage migrate --pod="my_pod" --fields="my_rel_field" --from="meta" --to="table"
Example: Migrate the field “my_rel_field” on the “my_pod” pod from table to meta storage
wp pods-pro-advanced-relationship-storage migrate --pod="my_pod" --fields="my_rel_field" --from="table" --to="meta"
Example: Migrate the field “my_rel_field” on the “my_pod” pod from table to BOTH meta and podsrel storage
wp pods-pro-advanced-relationship-storage migrate --pod="my_pod" --fields="my_rel_field" --from="table" --to="meta,podsrel"
Example: Migrate the fields “my_rel_field” and “my_other_rel_field” on the “my_pod” pod from meta to table storage
wp pods-pro-advanced-relationship-storage migrate --pod="my_pod" --fields="my_rel_field,my_other_rel_field" --from="meta" --to="table"
Example: Migrate the field “my_rel_field” on the “my_pod” pod from meta to table storage and then delete all data for that field stored in meta or podsrel
wp pods-pro-advanced-relationship-storage migrate --pod="my_pod" --fields="my_rel_field" --from="meta" --to="table" --delete-from="meta,podsrel"
Example: Migrate ALL relationship/file fields on the “my_pod” pod from meta to table storage
wp pods-pro-advanced-relationship-storage migrate --pod="my_pod" --from="meta" --to="table"
Example: Migrate ALL relationship/file fields on the “my_pod” pod from meta to table storage but do not save/delete anything
wp pods-pro-advanced-relationship-storage migrate --pod="my_pod" --from="meta" --to="table" --test
Example: Migrate ALL relationship/file fields on the “my_pod” pod from meta to table storage with debug information on various steps
wp pods-pro-advanced-relationship-storage migrate --pod="my_pod" --from="meta" --to="table" --debug