Forum Replies Created
-
AuthorPosts
-
COMCEPT
ParticipantThank you,
we have the AIO plugin.
Could you update that as well?COMCEPT
ParticipantThanks Anh,
That'd be great! We'd be able to grab the non-translated term/post, get the translation via polylang, and then create a new relationship with the new IDs so we'd be able (in theory) to automatically see it selected as the correct option in the relationship select.
If that's possible, it's a very welcomed improvement! ๐
COMCEPT
ParticipantThanks Anh, of course I can tell ๐
So we have these custom post-types and they all share common data; we then decided to store this shared data in a common custom table and some specific data in their respective post-type-specific custom tables.
We're hooking into the
get_post_metadataand theadd_post_metadataso that we can generalize the usage of the custom table plugin and render it "transparent" to other plugins such as Polylang.To do so we need to programmatically get the source/destination table, given a meta-key, where we need to retrieve/store its value.
Let's focus on writing data (because we just join the shared/common meta-data table upon reading so it's simpler).
Our meta writing function, in pseudo-code, looks more or less like this
add_filter('add_post_metadata', function ( $check, $object_id, $meta_key, $meta_value, $unique ){ if this_is_not_a_custom_post_type || the_meta_key_is_not_a_metabox_field return null; // This is where we select the table, based on the field_id/meta_key $table = com_get_obj_property( rwmb_get_field_settings( $meta_key, '', $object_id )['storage'], 'table' ); // This is so we update an existing ID in the custom table afterwards maybe_insert_id_in_custom_meta_table( $object_id, $table ); // Maybe we need to serialize the value if ( !empty($meta_value) ) $meta_value = maybe_serialize( $meta_value ); // Finally write the correct meta value in the correct table updating the correct ID $wpdb->update( $table, [$meta_key => $meta_value], ['ID' => $object_id] ); });As you can see, we dynamically need to grab the correct table based on the meta_key. That's why we'd need to have access to it (and we have, via the array casting trick).
A simple getter, would be enough. No need to have a setter or make it public.
COMCEPT
ParticipantHi Anh,
We're using Polylang Pro
COMCEPT
ParticipantHi Ahn,
is it possible to have an estimate of the release date?
I'm switching to Meta Box on several projects and I need to migrate ACF link field to something similar.
ThanksJanuary 16, 2020 at 5:02 PM in reply to: โ Hooking into get_post_metadata and add_post_metadata #17865COMCEPT
ParticipantThank you Anh,
I was hoping for some sort of higher level approach; an API responsible for retrieving/storing metadata from/to custom tables (for a specific post id) with some kind of validation, sanitization, serialization and so on. Maybe a set of functions/wrappers to take into account the way Meta Box stores the fields. Is this low-level approach the only possible one?
Thank you
-
AuthorPosts