Skip Navigation

[Resolved] 1. Relations not created and 2. automatic post title

This support ticket is created 3 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 10 replies, has 2 voices.

Last updated by katjaL 3 years, 5 months ago.

Assisted by: Jamal.

Author
Posts
#2111145

I have a child post (tarjouspyynto) which can have 4 different parents (juhlatila,esiintyja,vuokralaite,synttarikakku). All parents have the link to the same child post form. And the parent selectors there are properly populated when arrived to that page from parent.

Now I have 2 issues:

1. Only juhlatila relation is created by the form. For some reason other relations don’t get created even though the parent name is there in select.
2. The child posts are automatially named after the parent title with code below. It would be great if I could add condition to check parent’s post type and choose only that post for parent title. At the moment the title is like 
“FormpagetitleFormpagetitleFormpagetitleParentposttitle”

But of course at the moment the issue 1 should be solved first to create the condition.

add_action('cred_save_data','juhlatila',15,2);
function juhlatila($post_id, $form_data) {
if ($form_data['id']==4403) {

// set the values of fields in title and slug
$title = get_the_title($_POST['@juhlatila-tarjouspyynto_parent']).get_the_title($_POST['@esiintyja-tarjouspyynto_parent']).get_the_title($_POST['@vuokralaite-tarjouspyynto_parent']).get_the_title($_POST['@synttarikakku-tarjouspyynto_parent'])."-tarjouspyyntö";
$slug = sanitize_title($title).'-'.$post_id;

$my_post_data = array(
'ID' => $post_id,
'post_title' => $title,
'post_name' => $slug,
);

// Update the post into the database
wp_update_post( $my_post_data );

}
}

#2111377

Hello and thank you for contacting Toolset support.

To better assist you with this issue, I'd like to check this form closely. I would like to see if the parent posts are selected automatically or manually. And perform a small test. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

As you have said, once we fix the parent post assignment, we'll handle the automatic generation of the title.

#2111973

When we click on the button "Pyydä tarjous", for example from the post hidden link
We land in this URL hidden link
At this stage, we have a parent already selected(using URL parameter), but 3 other parents are not. Check this screenshot hidden link

If we submit the form without selecting the 3 other parents, it is expected that they won't be linked. And the custom code that will generate the title will not be executed as it is expected.

I run a test where I choose the other 3 parents manually and submit the form, the newly created post has all 4 parents linked, and the title was created correctly. This is the post hidden link

At this point, I don't see any issues. If you need the parent to be selected before the form can be submitted, make them required at the form level.

If you need the 4 parent posts to be automatically selected, you will need to modify how the link of the "Pyydä tarjous" button is generated to incorporate all other parents.

If I missed something, please let me know and I'll do my best to help.

#2112879

Thank you Jamal. It seems I was a bit unclear. The child post has and must have only one parent. It is not meant to have simultaneously 4 parents, but only the one from where the child post form is linked from. And for some mysterious reason, this works fine when a "juhlatila" post is as parent. But when you choose something else, say that "vuokralaite" for example and you create the child post, the relation for the vuokralaite parent in question is not created - even though it's there is select dropdown quite rightly pre-chosen.

#2113217

Can you provide a detailed example to help me understand this? Or can you record a screencast?
An explanation in detailed steps will be helpfull. Something like:
1. I go to xxx
2. I do xxx
3. I expect to have xxx
4. Instead, I get xxx

#2113279
Screenshot 2021-07-13 at 15.02.38.png

Ok, here you go, I use your example:
1. hidden link and I click "Tarjouspyyntö"
2. I fill the form here hidden link
3. I expect to have relation to parent "pallomeret..."
4. Instead I get no relation, check screenshot

But if I go to any juhlatila, I get the relation properly. Like this:
1. hidden link
2. hidden link
3. I get relation, check screenshot

#2113395

Well, If I go to hidden link the parent is already preselected as you can see on this screenshot hidden link
And if I submit the form, the created post has the parent correctly linked. Check this screenshot hidden link

Am I missing something?

#2113409

OMG Jamal, it seems the problem is not in Toolset, but in Admin Columns pro Toolset extension! Thank you for making that clear. Perhaps you have a clever idea to the post title issue too?

#2113437

It seems that the custom code that generates the post title works as expected. At least, that is what I noticed on my last tests.

Can you explain to me what's not working as you would expect?

#2113925
Screenshot 2021-07-14 at 8.06.57.png

The child post title should be constructed like this: "parentposttitle - tarjouspyyntö"
Now it's constructed also for those non existing parents and then the title is the title of the page where the form is ("Pyydä tarjous"). Attached you find what should be in green and in red the ones I would want to delete from the automatic title. So I would need some condition to check what is the parent of the post and choose only its' title and then add the "- tarjouspyyntö" in the end. Does this make sense?

#2114901

Hi Jamal, I think I make the title another way. My issue is resolved now. Thank you!