---
title: "Database Structure"
source: "https://docs.nexcess.com/software/kadence/iconic/linked-variations/database-structure/"
description: "The data for Linked Variations are stored in these two database tables: wp_posts: Linked Variations are presented as a Custom Post type with the key cpt_iconic_…"
vertical: "Software"
area: "Linked Variations"
date: "2023-08-08"
last_modified: "2023-08-08"
---

# Database Structure

The data for Linked Variations are stored in these two database tables:

**wp\_posts**: Linked Variations are presented as a Custom Post type with the key cpt\_iconic\_wlv.

**wp\_iconic\_woo\_linked\_variations**: The settings of Linked Variations such as product IDs, attributes, show images, etc., are stored in this custom table created by Linked Variation plugin. The database schema of this table is shown in the table below:

| Column | Type |
|---|---|
| id | int(11) |
| product\_ids | longtext NULL |
| attributes | longtext NULL |
| show\_image | tinyint(1) NULL |
| post\_id | bigint(20) NULL |
| style | text NULL |

Where **product\_ids** and **attributes** are arrays stored in [serialized format](https://www.php.net/manual/en/function.serialize.php).

## Programatically update Linked Variations

We have a helper function, `Iconic_WLV_Database::update_linked_variations_meta`, that can be used to programmatically insert/update linked variations with the PHP code. Creating a linked variation is a two-step process: First, create and insert a new post type, and then insert the linked variation data into the custom table wp\_iconic\_woo\_linked\_variations.

```
// Insert the post.
$post_id = wp_insert_post(
	array(
		'post_title' => 'new linked variation',
		'post_type'  => 'cpt_iconic_wlv',
	)
);

// Prepare linked variation data.
$data = array(
	'product_ids' => array( 30, 31 ),
	'attributes'  => array( 'pa_color' ),
	'show_image'  => 1,
	'post_id'     => $post_id,
	'style'       => 'button',
);

Iconic_WLV_Database::update_linked_variations_meta( $post_id, $data );
```
