Skip Navigation

[Resolved] Can I create a post relationship and only use it conditionally?

This support ticket is created 2 years, 6 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 – 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)

This topic contains 25 replies, has 3 voices.

Last updated by himanshuS 2 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#2168313

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Himanshu,

Was the staging site taken down ? As i'm trying to access it and it doesn't work.

Thanks,
Shane

#2168335

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Himanshu,

I've setup a test site for this and was able to confirm the exact symptoms that you're experiencing with your form.

I went ahead and escalated this to our 2nd tier team for further checks.

Thanks,
Shane

#2168341

Thanks, Shane. Appreciate your help.

#2170225

Shane,

Do you have a time for when this could be done? I am using conditional shortcode at a lot of places on the site and this is kind of a show stopper for certain functionality.

#2170275

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Himanshu,

Our 2nd tier team managed to have a look at this for you and was able see that the workaround using the conditionals is working.

I've updated the code on your test site to format the conditional code correctly and it now works.

You can check the form below.
hidden link

Please let me know if this helps.
Thanks,
Shane

#2170433

Thank you. It seems to be visible in the right format. A few questions -
1) What was the reason for not working?
2) Why is the toolset_access shortcode not working?

However, it does not seem to do the job of connecting to the parent post (job) using the code below . You can also try it on your end.

The code is in toolset custom code -> link-m2m-relationship-between-jobs-and-project-prompts

<?php
/**
 * New custom code snippet (replace this with snippet description).
 */

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.
add_action('cred_save_data', 'prowess_associate_multiple_related_posts_between_jobs_and_project_prompts',10,2);
function pprowess_associate_multiple_related_posts_between_jobs_and_project_prompts($post_id, $form_data) {
  $forms = array( form-id1, form-id2 );
  $relationship_1_slug = "job-to-project-prompt";
  $ms_field_slug = "job-post";
 
  if ( in_array( $form_data['id'], $forms ) ) // test if the form being submitted is in the list of form IDs we want to target
  {
    $ms_selections = $_POST[$ms_field_slug]; // the $_POST superglobal contains an array of the selected parent post IDs
    foreach($ms_selections as $ms_selection) {
      toolset_connect_posts( $relationship_1_slug, $ms_selection, $post_id); // while looping over selected parents, connect them to the new child post programmatically
    }
  }
}
?>
#2170519

I am also not able to connect the parent and child post using the code mentioned earlier in the thread. The whole point of using the generic field is to create a relationship programmatically.

The code snippet in toolset custom code - link m2m relationship between jobs and project

#2171099

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Himanshu,

1) What was the reason for not working?

Regarding the conditional i believe it had to do with the formatting and correct spacing.

2) Why is the toolset_access shortcode not working?

Based on the information from our 2nd tier team the access shortcode isn't meant to be used in a scenario like this hence why the access button isn't available on the form itself.

Regarding your hook I would suggest debugging a bit further to see if all your variables have the correct values.

I would perform a var_dump() on each of the variables to see what values are being passed. You should see the variable dump on the page when the form gets submitted.

Thanks,
Shane

#2171227

Posting again as I am not sure why this issue is in the user confirmation stage.

#2171317

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Himanshu,

Not sure what you mean by "Posting again as I am not sure why this issue is in the user confirmation stage."

However some amount of debugging is needed on your function to see what values are being passed into the variables.

It may be a case where the $ms_selections variable doesn't have the correct information.

I see that you're using a foreach to navigate through the options but we have to first ensure that it is an array or else it will fail.

Thanks,
Shane

#2171671

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.