Support Forum
I want to integrate a 3rd party software my WP install. Here's my challenge.
The software returns an array of JSON key pairs with the following characteristics:
1. Random quantity of JSON key pair arrays based on user interaction on the 3rd party platform
2. Multiple field types but limited to only four (4) types: text, number, url, color
3. Random custom field values
The challenge is the random number of JSON key pair arrays which means I don't know in advance how many custom fields per post I'll need. Although it will likely be less than 10 most times and almost never more than 25.
My question is what is the best approach for a solution to this challenge? I can think of two options:
Hi,
Thank you for reaching out.
How the key pairs relate to the meta boxes, 4 field types, and random value? Can you please give an example?
The 4 field types are: text/string, number, color code (which I guess could be text), image. The code has a true/false option but that isn't necessary to use for my purpose.
It's an image API so all the fields are attributes of one image. It's a multilevel array of attributes.
Here's a short example of the JSON. Any one image would have a random number of attributes/key pairs.
{
"template_name": "Facebook-Post-1200x900",
"api_key": "XXXXXXXXXXXXXX",
"modifications": [
{
"name": "background-image",
"image_url": "default",
"width": "1270.59px",
"height": "900px",
"visible": "true"
},
{
"name": "shape-0",
"type": "shape",
"background-color": "black",
"border-color": "initial",
"border-width": "initial",
"visible": "true"
},
Hi,
You can create your own function to get the number of modifications and items in each modification object and then use the loop to create the number of meta boxes. The field should be text
to use for all cases. Just like
add_filter( 'rwmb_meta_boxes', function() {
$modifications = get_the_modification_and_items();
foreach ( $modifications as $index => $modification ) {
$meta_boxes[] = [
....
]
}
return $meta_boxes;
} );
Hope that makes sense.