Home › Toolset Professional Support › [Resolved] Hook after submitting a new connection in a relationship form
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
Tagged: CRED API, Toolset Forms
Related documentation:
This topic contains 13 replies, has 2 voices.
Last updated by meirk 5 years, 11 months ago.
Assisted by: Nigel.
I have a custom field in a intermediate relationship post called "counter"
I would like to hook in a way that each time someone press the submit button to create a new connection - the counter is added by +1 (even if the connection had been already created before)
is that possible?
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
I think the hook you are looking for is toolset_association_created, which is triggered whenever two posts are connected.
bsd
Thanks - it works
but what i need also as i wrote is the following:
I would like that when the submit to create a new relation is pressed, even if the relation alreaddy exists - a custom field in the intermediate custom post called "counter" is set to counter++.
How to do that?
The idea is that i have a "cause custom post" and a "psalms cap" custom post.
people will read a psalms post and than press the submit ( which will be replaced by the words "finished praying this psalms cap" and than when he press the submit - two things shoul happen:
1- if this is the first time someone read this psalms - the submit button link the psalm post to the "cause" custom post and the counter add counter++ meaning this post was read once and connected to parent cause post
2- if there is already a relation between a psalms post and a cause post (caused by a previous reader), the submit will anyway leads to add the counter to counter++ meaning this psalms post was read twice and so on
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
OK, then that hook won't help, it would only be fired the first time you create the connection.
I think you need two different forms (where the form content is hidden so that the user sees only the form submit button).
You need a form to create the relationship, i.e. to connect the psalm and cause posts.
And you will need a form to edit the existing connection.
Where you plan to display the submit button, you will need to use conditional display to show either the publish connection form (if there is none currently) or the edit connection form (if there is). You'll likely need a custom function to test whether there are any existing related posts.
In both cases you would use the cred_save_data hook to run a snippet of code that creates or increments the counter.
Each of these are covered by the documentation listed below, but let me know if you try to implement and get stuck on something specific.
https://toolset.com/documentation/post-relationships/how-to-build-front-end-forms-for-connecting-posts/
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
bsd
"And you will need a form to edit the existing connection."
do you mean a intermediate edit post form?
could you start giving me a direction in the codes (i am not a professional php prpg)
also i thought abot another posibility:
maybe just place a button that while submited do 2 actions:
1 - try to connect the two posts by hook function
2- after 1 add couter++
what do you think?
Also tried this code for 1 time relationship connect:
add_action( 'toolset_association_created', 'handle_association_created', 10, 5 ); function handle_association_created( $association_slug, $parent_id, $child_id, $intermediary_id, $association_id ) { $value1 =get_post_meta( $intermediary_id ,'wpcf-cause-tehilim-read-counter',true );echo ' '; $value1++; }
it doesnt work - any idea? (variables are ok when i echo them...)
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Could you explain a little more about the connections between the post types causes and psalms?
You say if someone clicks a button while reading a psalm it should connect to a cause post (if not already connected), but which cause post?
How are the psalm posts related to the cause posts (non-technically)?
If there is some kind of existing connection between them, should they not already be related (via a Types relationship), with an initial counter value of zero, which gets incremented whenever anyone clicks the button upon completing reading the psalm post?
We are talking about technical solutions, but I don't really understand the use-case so I can't confidently recommend a particular solution.
Ok, i will explain exactly my target:
I am buiding a site that have 3 custom post types:
1- prayers
2- psalms cap.
3- Causes
people should get in the site - create a cause and share with friends to pray psalms for the cause.
Now when someone choose a cause - a Psalm cap is showed in the screen to the prayer and after reading, the prayer submit a button called "finished reading"
Than the data base should be updated in causes post ore psalms code to store all the psalms already prayed for a specific cause.
When all the cap of psalms was prayed by readers, a counter should point that the book was read once for the specific cause, and start a new reading cycle.
Than people who enter the cause should see how many psalms and books were prayed for the cause he choosed.
Could you help me to decide exactly how to do it?
parent childs relations?
maybe a special post type to store all the read story relations?
Thanks
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
Sorry, I think I'm supposed to know what a "Psalm cap" or "cap of psalms" is, but I don't.
How are these psalm posts related to the cause?
When someone creates a cause, do they assign some psalm posts to the cause, and when another user views a cause post these psalms are listed and the user can click to say they read it.
You will be keeping a tally of how many different users read each psalm.
And once all of the psalms have been read (by an individual who has to read all of them, or it doesn't matter who reads them as long as each psalm has been read by someone) the cause post should record that it has been read?
I'm sorry if I sound confused, but I still don't understand your description of what is involved.
Sorry, will try to be more clear:
"Psalm cap" is a specific chapter of the book of psalms from david the king of israel.
How are these psalm posts related to the cause?
"When someone creates a cause, do they assign some psalm posts to the cause"
No, all the chapters are going to be red by many people - it doesnt matter who read each chapter. the target is that all the book chapters wiil be read once , and than twice and so on...
"and when another user views a cause post these psalms are listed and the user can click to say they read it."
each user get one specific chapter of this "number of cycle reading" - and after he submit meaning that he red it - another chapter is offered to him to read - or he can just stop reading chapters for this cause.
"You will be keeping a tally of how many different users read each psalm."
I would like to keep only the number of redaing persons for each cause, and progressing data of reading the book, and how many times the book was read for this specific cause...
"And once all of the psalms have been read (by an individual who has to read all of them, or it doesn't matter who reads them as long as each psalm has been read by someone) the cause post should record that it has been read?"
I doenst matter who read - the target is that the book was read by many persons together.
for sure i have to show to each new person who gets in a cause - a specific chapter who wasn't benn read for this cause in this "cycle" of reading the book.
thanks
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
OK, so let me make sure I have this straight, then I can think about the solution.
- A new cause is published, and the link to that cause is shared so that other (unregistered) users can participate in the shared reading of the psalm chapters
- There is no explicit connection between the psalm chapters and the cause initially, because all of the chapters must be read (by someone) to complete one reading
- Once all of the psalm chapters have been read, a new reading cycle for the same cause begins, and we will be keeping track of how many reading cycles have been completed for a given cause
A new reader visiting the cause will be presented with a currently un-read psalm chapter to read. A random un-read chapter or are they presented in sequence?
Does it matter that multiple people may read the same chapter within the same reading cycle? Say one visitor is presented with the next un-read chapter and begins to read it. Another visitor comes along immediately afterwards and is presented with the same un-read chapter (they don't know that someone else has already started but not completed reading it).
bsd
Yes - i think this is clear now!
"A new reader visiting the cause will be presented with a currently un-read psalm chapter to read. A random un-read chapter or are they presented in sequence?"
Doesn't matter random or sequential - but maybe if he wants to choose another sequential or random, it should be possible (like if the chapter is to long for him to read - and he prefers a short's one)
"Does it matter that multiple people may read the same chapter within the same reading cycle? Say one visitor is presented with the next un-read chapter and begins to read it. Another visitor comes along immediately afterwards and is presented with the same un-read chapter (they don't know that someone else has already started but not completed reading it)."
If this scenary happens - no matter - and we should count that this chapter was read just one time to this cycle...
Thanks again.
I will be in work again from saturday (tomorrow) night . Hope you can think about this challenge
Languages: English (English ) Spanish (Español )
Timezone: Europe/London (GMT+00:00)
OK, I'm at the end of my day, I can think in more detail about it Monday, but in terms of the underlying structure of how this is set up, I see it like this:
You have a Cause post type.
You have a Psalm Chapters post type, and you publish a post for each chapter.
You also create a Readings post type.
You set up a one-to-many relationship between causes and readings, so each cause can have multiple readings.
You also set up a many-to-many relationship between readings and psalm chapters. Each "reading" will require reading of all the chapters, and the chapters can be read many times.
For a given reading you will want to display (or choose from) the unread chapters, so you would either connect a chapter to a reading when it has been read and choose from chapters that have no connection, or you could start out with the reading connected to all chapters and then delete the associations once they had been read so that you would be choosing from chapters which did have a connection to a reading.
When a reading had been completed a new reading post would be published.
The cause post could automatically display the number of reading posts (how many readings) and only display the reading (i.e. the chapters to choose from) from the current unfinished reading.
There are details to be worked out, but I think that is a sound basis for developing this.
Let me know your comments and I'll follow up after the weekend.
Thanks for the database - relationships ideas
This really helped me, and i've already made the base of the site
Thanks