Support has been upgraded!
The Support Forum is closed. Not to worry! Providing the top quality support you expect and we're known for will continue! We're not ending support, just changing where you submit requests. This will provide you with the best experience possible.
Premium Support
Have you purchased an addon for Connections such as one of our premium templates or extensions with a valid license and you need help?
Please open a Support Ticket in your user account.
Free Support
Are you using the free Connections plugin? Don't worry, you are still very important to us! We are still providing you with the same high quality support that we're known for.
Please open a new support topic in the WordPress support forums for Connections.
Tagged: 8.28.5
- This topic has 16 replies, 2 voices, and was last updated 4 years, 7 months ago by
Steven Zahm.
-
AuthorPosts
-
10/31/2018 at 11:03 am #476104
Joshua Tempesta
ParticipantHello Steven,
Thanks again for your previous technical help. I’m not sure if this kind of question is allowed but I would really appreciate some advice.
I had
a question about the way the wp_connections table columns ‘addresses, phone_numbers, email, etc’ get populated.I’m trying to write a small script to automatically populate our business directory.
However when I manually insert a row into the wp_connections_address table the addresses show in the entry the first time you load them but then get deleted when you update the record.I assume it’s because I’m not populating the wp_connections addresses column with the correct json?
How do I correctly populate these dynamically generated columns?
10/31/2018 at 12:29 pm #476108Steven Zahm
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 theid
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 theid
index of each address matches theid
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!
11/15/2018 at 9:10 pm #477168Joshua Tempesta
ParticipantI created a proper WordPress plugin and took your advice and did it without manual SQL. It automatically populates the directory based on RegistrationMagic submissions.
Everything is working great however I had a couple simple questions:
- How do I assign the user column to a new cnEntry? I see private fields in the code but no way to set them. I tried instantiating an $entry via constructor but must be doing it wrong. Can you give an example?
- Can you explain further on how to assign multiple categories to the cnEntry?
Thanks again for the help.
11/16/2018 at 12:00 pm #477196Steven Zahm
Keymaster@ Joshua
RE: How do I assign the user column to a new cnEntry?
$entry->setUser( $id );
$id
is the WP user ID.RE: Can you explain further on how to assign multiple categories to the cnEntry?
Connections_Directory()->term->setTermRelationships( $entry->getId(), array( $term1, $term2, $term3, [...] ), 'category' );
The
$term
variables are the category ID numbers. The array contains the ID of all categories you wish to attach to the entry. It basically works the same way that the core WP function to attach categories to posts;wp_set_object_terms()
.Hope that helps!
11/16/2018 at 12:01 pm #477197Steven Zahm
Keymaster@ Joshua
Ca you share a link to your plugin? I’d like to see it!
11/20/2018 at 12:02 pm #477457Joshua Tempesta
ParticipantSteven,
You can have the full source code once I’m finished. It’s not published yet. I’m creating it for a non-profit i work with. Feel free to do whatever you want with it ^_^
I am having difficulties resolving a category name to an id.. I’m still quite new to WordPress. I am using the following code:
$category_id = get_cat_ID($category); txtlog("category id for: ".$category." : ".$category_id); if($category_id > 0) Connections_Directory()->term->setTermRelationships( $entry->getId(), array($category_id), 'category' );
log:
2018-11-20 04:56:08pm : category id for: Law, Finance & Insurance : 0is there a different way I’m supposed to resolve connection category names/slugs to ids?
Thanks again for the help
11/20/2018 at 12:57 pm #477459Steven Zahm
Keymaster@ Joshua
The
get_cat_ID()
is a core WP function to retrieve one of its category ID by name. You need to use the Connections equivalent found in theclass.terms.php
file.$category_object = cnTerm::getBy( 'name', $category_name, 'category' ); var_dump( $category_object ); $category_id = $category_object->term_id; var_dump( $category_id );
Hope that helps!
01/27/2019 at 10:23 pm #482811Joshua Tempesta
ParticipantHey Steven, I was wondering if you had some time to provide an example of adding a website link programmatically?
I would really appreciate it, as always!
01/28/2019 at 12:29 pm #482853Steven Zahm
Keymaster@ Joshua
RE: provide an example of adding a website link programmatically?
It is much like adding an address. Here’s and expended example from my original reply.
$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', ) ) ); $entry->links->add( new cnLink( array( 'title' => 'Connections Business Directory Plugin for WordPress', 'url' => 'https://connections-pro.com', ) ) ); $result = $entry->save(); if ( FALSE !== $result ) { $default = get_option( 'cn_default_category' ); Connections_Directory()->term->setTermRelationships( $entry->getId(), $default, 'category' ); }
Hope this helps!
02/03/2019 at 6:17 pm #483444Joshua Tempesta
ParticipantThank you once again for the excellent support, Steven.
- How do I assign the user column to a new cnEntry? I see private fields in the code but no way to set them. I tried instantiating an $entry via constructor but must be doing it wrong. Can you give an example?
-
AuthorPosts
You cannot reply to this support topic. Please open your own support topic.