[Resolved] How to edit or delete parent post on frontend
This thread is resolved. Here is a description of the problem and solution.
Problem:
A View queries intermediate posts so as to be able to display fields from a parent post. How to delete relationships or edit a relationship (e.g. assign a different parent)?
Solution:
The context of the View which queries the intermediate posts in the relationship means that you can use the normal cred_delete_post_link or toolset-edit-post-link shortcodes to delete or edit the relationship.
Is it possible for a user on the frontend to change or delete a parent post?
For instance, I have:
SONG (parent) PUBLISHED BY (child) PUBLISHER (parent)
if the PUBLISHER (parent) changes or needs to be removed (because there's no longer a publisher), can that be done on the front-end with a CRED edit link? I know how to set-up an edit link for editing fields, but not for this situation.
I would try creating a specific content template to hold the cred edit form to edit the parent. I'm not sure but I think when you link to that from the child post the context will be the child post, so you should be able to employ the same technique as above using the wpv-post-id shortcode with id attribute to set the post attribute of the cred_form shortcode to specify the parent.
There's only one way to know, which is to try it.
Can you try it and if it doesn't work let me know and I'll investigate further?
I will try. The problem is the child is an unseen intermediary post that cred generates an auto title for.
Maybe I could of/ should of set this up differently, but I think I determined - after countless hours, that this was the best way for my particular project.
I'll explain a little:
Song (parent) intermediate (child) Publisher (parent) - (needs to be many to many)
There are 3 forms
1. A form to create the Song with fields for meta data
2. A form to create the Publisher name
3. A form to attach the created song to the publisher (this form is generated from the child, as it has to be, and doesn't contain a title field, which is why the intermediary child post title gets auto generated) The reason for this is so that in this form the user can just select the track in a dropdown and the publisher in a dropdown and hit submit and they are linked.
Then, to view this data I have a template which shows, on one page, the Song with fields and (with a view in the same template) the parent relationship.
So you see, the child is really just a placeholder that works in the background and never gets seen by the user.
It doesn't seem an ideal solution.
Frankly, if I can't get toolset (which is a great plugin!) to do what I need I might have to try something else.
You guys are great though, and I very much appreciate the support.
If you have any ideas about setting this up differently, that would be appreciated.
I assume you have a template for displaying a song post, and this template displays the connected publisher using a View which queries the intermediate post type and displays fields from the parent publisher using the id attribute, e.g.
Publisher: [wpv-post-title id="$parent"]
Now if your user wants to delete the publisher from the current song, they don't want to delete the publisher post itself, they want to delete the relationship, i.e. the intermediate post.
Well that View which is used to display the parent post fields is querying the intermediate posts that store the relationship, so that's the post you want to delete (or edit).
So in the Loop Output section of that View you already have the correct context for the cred_delete_post_link or the toolset-edit-post-link shortcodes, to either delete the relationship or to edit it (e.g. change to a different publisher).
So unless I'm missing something, it's maybe not so complex after all, though I can see how you might be going round in circles with this.