Home › Toolset Professional Support › [Resolved] Adding Child relationships with Elementor
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.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 14:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Jamaica (GMT-05:00)
Related documentation:
This topic contains 11 replies, has 2 voices.
Last updated by Shane 4 years, 5 months ago.
Assisted by: Shane.
As the title says, I'll explain in detail.
Currently, there's no support to place an edit page link into an elementor template without inserting the post content form into the page. Which I didn't want to do as I didn't want to use content templates as a solution.
After searching around, I found a way around the fix;
This is one of my previous tickets which explains the situation
https://toolset.com/forums/topic/edit-content-link-in-elementor-not-working/
However, I'll explain in detail here what I would do to create the edit link to an external form from an elementor page.
In this example I am going to use a website not related to this one.
1. Create a CPT for Players
2. Inside CRED 'Create a Player'
3. Inside CRED 'Edit a Player'
4. Create a page and edit with elementor to show my CRED 'Create a Player' Form.
5. Insert a function into my Custom code area of Toolset and click activate.
function func_display_partner_edit_form() { if(isset($_GET['partner_id'])){ return do_shortcode("[cred_form form='edit-user-profile' post='".$_GET['partner_id']."']"); }else{ return "To edit your Player profile, please select from the above link(s)."; } } add_shortcode('display_partner_edit_form', 'func_display_partner_edit_form');
This code links the views to the form.
6.Next I want to create 2 new views.
a) Create a view for the Player page, to show an edit link; (View Name: Player page edit link)
I will untick "Don't include current page in query result"
(we want to include the current page, because if we don't the link won't show for the current page)
This will have 2 filters;
Filter 1: Select posts with the author the same as the current logged in user.
(This will only show the edit link on the Player page to the current logged in user who is the author of the page)
Filter 2: Include only posts with IDs set by the View shortcode attribute "ids" eg. [wpv-view name="view-name" ids="1"]
(This will show just 1 edit link, which is related to the page it is currently on)
(Without this filter, edit links for all Player pages, would show on the Player page, that the author owns)
The code for this would be;
[wpv-layout-start] [wpv-items-found] <!-- wpv-loop-start --> <wpv-loop > <center> <a href="/edit-your-profile/?partner_id=[wpv-post-id]">Edit Your Profile</a></center> </wpv-loop> <!-- wpv-loop-end --> [/wpv-items-found] [wpv-no-items-found] <strong>[wpml-string context="wpv-views"][/wpml-string]</strong> [/wpv-no-items-found] [wpv-layout-end]
b) Create a view for the external page, hosting the form (to show above the form, for ease of access to all currently authored posts.)
(View Name: Dashboard edit link)
In this case, it doesn't matter if we tick "Don't include current page in query result", because we aren't looking to edit this page, where the view will be shown.
I will only filter by 1 item here;
Filter 1: Filter 1: Select posts with the author the same as the current logged in user.
(This will all links the author owns as we have not selected the second filter as we did earlier)
The code for this;
[wpv-layout-start] [wpv-items-found] <!-- wpv-loop-start --> <wpv-loop > <center> <a href="/edit-your-profile/?partner_id=[wpv-post-id]">Edit Your Profile [wpv-post-title]</a></center> </wpv-loop> <!-- wpv-loop-end --> [/wpv-items-found] [wpv-no-items-found] <strong>[wpml-string context="wpv-views"][/wpml-string]</strong> [/wpv-no-items-found] [wpv-layout-end]
7. With the above now, I can insert the edit link into the player page using the following shortcode.
[wpv-conditional if="( '[wpv-post-author format='meta' meta='ID']' eq '[wpv-current-user info='id']' )"][wpv-view name="edit-player-view" ids='[wpv-post-id]'][/wpv-conditional]
Notice the above works with the filters to produce a single edit link for the page that we're (the author is) on.
8. On my external page(Dashboard); (Creating and showing the Edit Player Profile form)
a) I will insert a heading - "Edit your Player Profile"
b) Insert the view "Dashboard edit link"
c) Add the following shortcode;
<center>[display_partner_edit_form]</center>
(When a link is clicked, this will open the form on this page.)
If we've done this correctly, everything should be set up to edit a player page from both the player page itself and the dashboard which we created for players ease of use.
Now to the main point of this ticket.
I have Created 2 CPT.
1. Parks
2. Caravans Stock
I have created a relationship between both CPT with a 1 to Many. (Park(1) to Caravan Stock(*))
I want to insert a link from the Park page, to allow people to submit a new stock entry onto a park.
I have tried to follow this article;
https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/#creating-forms-when-a-parent-post-is-preselected
This would mean I need to use a content template, rather than showing my form within elementor.
Using the example above, the way around the edit post links with Elementor, would I be able to do something similar for the Add Caravan Stock to Park link?
I am sorry if this is very long winded.
Hi Hayley,
Thank you for getting in touch.
What you can try doing is creating adding the form to a page itself and manually linking to that form.
This means you will need to edit the relationship field in the form and set a URL parameter attribute. See Screenshot
Then you will create a link and add it to the parent post template like this.
<a href='mywebsitelink.com/linktochildpostform/?my_id=[wpv-post-id]'>Click to Create Child</a>
Once you've set this up correctly when you link to the child form page from this URL you should get the parent Auto selected.
Please let me know if this helps.
Thanks,
Shane
Shane,
I've managed to add the link to the page which shows the correct wpv-post-id.
I am struggling to understand what I am supposed to put within the CRED URL parameter field to get the page ID to match the relationship form with the page.
I've tried a few ways based on the documentation available. I think I am currently just overwhelmed a little.
Thank you for your continued support.
Hi Hayley,
You can actually add anything you want, meaning any relevant name you can add. Just so long as you are passing this parameter in the URL.
Thanks,
Shane
You are right!
What wasn't working for me earlier was this
{{urlparam='my_id'}}
However putting the correct spacing before and after the brackets solved the issue I was having.
{{ urlparam='my_id' }}
So, a related question, I'd like to create a link now, using similar theory, to delete the relationship.
Should I create a new thread for this? Or is this completely related, considering everything is already here?
Hi Hayley,
Happy this helps.
When you say Delete the relationship are you referring to deleting the post relationship itself so it becomes an orphan or are you referring to deleting the post.
Thanks,
Shane
Shane, thank you for following up.
I would like to allow my users to make a post an orphan.
Keeping the post is preferred.
Hi Hayley,
I doubt the method we have been using will work here. This is because you will require an edit form in order to delete the relationship.
You will need to edit the child post and then set the relationship to a "not set" value and then update the post. Not sure if you've already setup an edit form that works with Elementor.
Can you confirm this ? If it already works then you will need to generate the Edit form for the post and then add a link to that edit form that will allow you to edit out the relationship.
Thanks,
Shane
Hi Shane,
Thank you again for coming back to me.
I can confirm that an edit form will be made using the above method.
Inserting the edit link onto the caravan stock page.
Let me implement the edit form for the Caravan stock and I'll get back to you once I've done that.
It'll be tomorrow when I do this now as I've run out of time today to do anymore work on the site.
Is that OK?
Hi Hayley,
Thats ok, just respond once you're able to test this.
Thanks,
Shane
Hi Shane, hope you're well.
So I managed to create the edit form etc.
I've managed to figure out how to make a child post an orphan.
I think what I want to do is create a link which uses the URL Parameter to 'not set' a park and after click, redirects the user to another page which says;
"Are you sure you want to remove the stock item from the park?
If not, click here"
I will hide the relationship field and just have a submit button.
What would I enter into the URL parameter to select the 'not set' option?
Hi Hayley,
The clearing is set by clicking the "x" on the select field that hosts the relationship.
I tried to use some javascript to simulate the clicking of this button but it doesn't seem to work. Perhaps you can try passing 0 into the URL and see if that helps.
Thanks,
Shane