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.6.5
- This topic has 7 replies, 2 voices, and was last updated 9 years, 2 months ago by
Alex M.
-
AuthorPosts
-
05/15/2017 at 6:16 pm #422968
Alex M
ParticipantHi Steven,
thanx again for your connections-plugin – it helps me a lot!
I know, my question is not really support-related. I still hope, the answer is just two lines of code for you and you find the time:I need to update the “district”-data of the address of one entry via a cronjob. So the code is not in the plugin. At the moment I have this
// get the addresses-entry of one single entry $result = $wpdb->query("SELECT addresses FROM wp_connections WHERE id=$temp_id"); $row = $result->fetch_assoc(); $string = $row['addresses']; $addresses = unserialize($string); // change the value of "district" $new_district = $addresses[0]->district +1; ... // Code to put $new_district back into the addresses-Array // Update addresses-array in DB $sql_new = "UPDATE wp_connections SET addresses WHERE entry_id=$temp_id"; $prep_new = $wpdb->prepare($sql_new); $prep_new->execute();Unfortunately I am really not familiar with arrays or even arrays in databases.
Do you see, what I am trying to do and can you help?Thank you,
Alex05/16/2017 at 9:39 am #423073Steven Zahm
Keymaster@ Alex
Three things…
- You need to update the district value within the addresses array. Your code example writes just the new district value to a new variable.
- You need to serialize the array before saving it back to the database.
- The example code is not actually writing any value back to the database. The example code I think will just empty the addresses value.
Hope this helps!
05/25/2017 at 6:23 am #424021Alex M
ParticipantHi Stephen,
thank you for you reply.
Since I am not that familiar with arrays your answer does not help as I hoped it will.
I know my example code is not working. I just wanted to visualize what I would like to do.
I was hoping you could provide me the exact code line to
1. update the value of the “district” with a new value
2. the sql-term to update the addresses array in the databaseThank you,
Alex05/25/2017 at 10:25 am #424067Steven Zahm
Keymaster@ Alex
re: Since I am not that familiar with arrays your answer does not help as I hoped it will.
Do this instead so you do not have to deal with arrays or manually accessing the database at all:
// Get the entry you wish to modify. $data = Connections_Directory()->retrieve->entry( 42409 ); // Setup the entry. $entry = new cnEntry( $data ); // Get the address, by id, that you wish to change the district field. $address = $entry->addresses->get( 38437 ); // Set the new value for the district field. $address->setDistrict( 'new' ); // Update the address in the entry with the modified address. $entry->addresses->update( 38437, $address ); // Save the changes back to the database. $entry->update();- Change
42409to the entry you wish to update. - Change
38437to the address id you wish to update the district.
Does that help?
06/13/2017 at 10:37 am #425850Alex M
ParticipantHi Steven,
this actually helped a lot!!
I did not know I could use the connections-functions in a cronjob as well.Sorry for the late response, but my computer broke down.
Thank you again for your help and great support!!
06/13/2017 at 12:03 pm #425860Alex M
ParticipantOops, I tested with fixed numbers instead dynamic IDs …
How do I get the address-id if I have the entry-id?
Is there a function too?06/13/2017 at 12:58 pm #425862Steven Zahm
Keymaster@ Alex
re: How do I get the address-id if I have the entry-id?
Look in the database. In the connections_addreses table, there is an entry_id column which will match the etrny_id you want to edit.
06/14/2017 at 3:17 am #425905Alex M
ParticipantHi Steven,
thank you for your answer.
I already had the database-query and it did not work, so I thought of some different function. Did not work as well.
At the end of the day I had a wrong variable earlier … :o/Now everything is fine. Thanx again for your time!
-
AuthorPosts
You cannot reply to this support topic. Please open your own support topic.
