Carbon_Fields\Field\Association_Field::process_value PHP Method

process_value() public method

The relationship data is saved in the database in the following format: array ( 0 => 'post:page:4', 1 => 'term:category:2', 2 => 'user:user:1', ) where the value of each array item contains: - Type of data (post, term, user or comment) - Subtype of data (the particular post type or taxonomy) - ID of the item (the database ID of the item)
public process_value ( )
    public function process_value()
    {
        $raw_value = maybe_unserialize($this->get_value());
        if (!$raw_value) {
            $raw_value = array();
        }
        $value = array();
        foreach ($raw_value as $raw_value_entry) {
            if (is_string($raw_value_entry)) {
                $value_pieces = explode(':', $raw_value_entry);
            } else {
                $value_pieces = array_values($raw_value_entry);
            }
            $item = array('type' => $value_pieces[0], 'subtype' => $value_pieces[1], 'id' => $value_pieces[2], 'title' => $this->get_title_by_type($value_pieces[2], $value_pieces[0], $value_pieces[1]), 'label' => $this->get_item_label($value_pieces[2], $value_pieces[0], $value_pieces[1]), 'is_trashed' => $value_pieces[0] == 'post' && get_post_status($value_pieces[2]) == 'trash');
            $value[] = $item;
        }
        $this->set_value($value);
    }