10/31/2018 at 12:29 pm
#476108
Keymaster
@ Joshua
The addresses column in the connections table is a serialized array, not JSON. the array should have an id index whose value matches the id of the address in the addresses table.
So, you should insert the address into the addresses table, get the address id and then serialize all addresses. Ensure the id index of each address matches the id assigned to the address in the addresses table.
Perhaps using Connections to add entries and addresses is better than manually manipuliating the DB.
Here’s the bear minimum to insert a new entry with an address into Connections:
$entry = new cnEntry();
$entry->setStatus( 'approved' );
$entry->setEntryType( 'organization' );
$entry->setOrganization( '~Test' );
$entry->addresses->add(
new cnAddress(
array(
'line_1' => '1600 Pennsylvania Ave NW',
'city' => 'Washington',
'state' => 'DC',
'zipcode' => '20500',
)
)
);
$result = $entry->save();
if ( FALSE !== $result ) {
$default = get_option( 'cn_default_category' );
Connections_Directory()->term->setTermRelationships( $entry->getId(), $default, 'category' );
}
Hope this helps!
