Skip Navigation

[Resolved] Difficulty Storing Related Post

This support ticket is created 6 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.

Our next available supporter will start replying to tickets in about 0.42 hours from now. Thank you for your understanding.

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 47 replies, has 4 voices.

Last updated by Shane 5 years, 4 months ago.

Assisted by: Shane.

Author
Posts
#914073

Hi Christian,

Any thoughts on why the relationship wasn't saving after updating to your new version of the code?

- Aaron

#914420

Not sure offhand, could you copy + paste the exact code you are using here for me to review?

#914421

Sure - here you go. Maybe I got something wrong piecing it together with the forms array and the content you modified from the original version.

add_action('cred_save_data', 'toolset_fix_layout_relationship_bug',10,2);
function toolset_fix_layout_relationship_bug($post_id, $form_data) {
  // one array for each form
  $hash = array(
    array(
      'id' => 198,
      'slug' => 'household-household-term',
    ),
    array(
      'id' => 507,
      'slug' => 'product-listing_ad',
    ),
	array(
      'id' => 532,
      'slug' => 'ad_ad-resposne',
    ),
	array(
      'id' => 534,
      'slug' => 'ad_ad-resposne',
    ),
	array(
      'id' => 735,
      'slug' => 'group_conversation',
    ),
	array(
      'id' => 735,
      'slug' => 'member-profile_conversation',
    ),
	array(
      'id' => 762,
      'slug' => 'group_group-member',
    ),
	array(
      'id' => 760,
      'slug' => 'group_group-member',
    ),
	array(
      'id' => 228,
      'slug' => 'household_household-child',
    ),
	array(
      'id' => 207,
      'slug' => 'household-term-household-course',
    ),
	array(
      'id' => 399,
      'slug' => 'product-listing_household-material',
    ),
	array(
      'id' => 399,
      'slug' => 'household-course_household-material',
    ),
	array(
      'id' => 381,
      'slug' => 'household-child_household-enrollment',
    ),
	array(
      'id' => 381,
      'slug' => 'household-course_household-enrollment',
    ),
	array(
      'id' => 447,
      'slug' => 'household-child_household-transcript',
    ),
	array(
      'id' => 328,
      'slug' => 'product-listing_product-review-ext',
    ),
	array(
      'id' => 340,
      'slug' => 'product-listing_product-review',
    ),
	array(
      'id' => 340,
      'slug' => 'household-child_product-review',
    ),
  );
   
// closure to find the matching array hash item and slug
  $find = function( $var ) use ($form_data)
  {
    $el = ($var['id']==$form_data['id']);
    return $el;
  };
 
  // create an array of form IDs where you want to apply this code
  $forms = array_column( $hash, 'id' );
 
  if ( in_array( $form_data['id'], $forms ) )
  {
    // find the slug array in the matching hash item and use it to connect the parent post
    $thisHash = array_filter( $hash, $find );
    $slugs = $thisHash[array_keys($thisHash)[0]]['slugs'];
    foreach( $slugs as $slug ) {
      $parent_id = $_POST['@' . $slug . '_parent'];
      $parent = toolset_connect_posts( $slug, $parent_id, $post_id );
    }
  }
}
#914726

Hi Christian,

Any luck on this? I'd like to get this one wrapped up today for my initial test-market launch happening tomorrow. Thanks.

- Aaron

#914792

The key in the $hash array should be slugs, not slug, and you should use an array of slugs even if there is only one relationship for that form:

'slugs' => array('group_group-member'),
#914795

Thanks - all fixed! I think the workaround is functional and I'll just stay tuned for a permanent fix.

- Aaron

#923231
temp3.jpg
temp2.jpg
temp1.jpg

Hi Christian,

Sorry to bug you on this workaround code again. If you recall, you just helped me with the following ticket:

https://toolset.com/forums/topic/custom-field-not-saving/

I realized the original PHP error message was still occurring after resolving the other ticket:

PHP Warning: array_key_exists() expects parameter 2 to be array, boolean given in /home/aaronmckeon/public_html/wp-content/plugins/wp-views/embedded/inc/wpv-shortcodes.php on line 3229

Upon digging deeper, I've now realized that the post relationship is being added twice. I'm not sure, but I think it could be related to the workaround code you provided. In form 735, the following hidden fields provide parent post data:

    <div class="hidden">
    	[cred_field field='@group_conversation.parent' value='[wpv-attribute name="groupid"]' class='hidden' output='bootstrap']
      	[cred_field field='@event-conversation.parent' value='[wpv-attribute name="eventid"]' class='hidden' output='bootstrap']
    	[cred_field field='@member-profile_conversation.parent' value='[wpv-post-id]' class='hidden' output='bootstrap']
    </div>

Depending on where the form is being displayed, it will always be given a member-profile parent, but one or both of the group_conversation or event-conversation ID's will be zero (they will never both have a non-zero ID since the message is either being posted under a group or under an event). I'm wondering if this is somehow causing your workaround code to create two connections each time the form is submitted? Can you comment? One option could be to create separate forms depending on where the form is being displayed, but I'd rather only have one form to manage. Let me know if you think this issue could be related. Attached are three screenshots taken during one submission form from an event page. Thanks.

- Aaron

#923536

No problem, remove this item from the hash if its connections are being duplicated. A duplication indicates that the redirect Layout bug isn't being manifested for this Form. Remove it, then test again and confirm your relationships are being defined only once for this new Conversation, as expected.

#923691

Okay I can confirm it's no longer duplicating the post connection now that I removed it from the hash, although the PHP error message is still there. Probably something unrelated to this thread.

Thanks.

- Aaron

#1189043

Hi, the code workaround we provided for this issue should no longer be necessary. The fix for the problem has been included in a recent plugin release. Let me know if the problem is not completely resolved.

#1242613

Hi Christian,

I've noticed that I still have some forms that are not storing related posts properly. Here are the relevant pages:

- Form 399: adds a product to a course
- Snippet "snippet-modify-post" lines 56-68: changes new post title to be identical to the parent post's
- Snippet "snippet-toolset-workaround" currently disabled since supposedly no longer required

Form 399 can be tested on the front end through the following directions:

1) Go to hidden link
2) Scroll to "Course Materials" and search for "Uncle Tom's Cabin" and click Add Material
3) Check the "Household Material" that's created and you will see that it doesn't save the related posts

Can you please assist? You may need to have me send you a current password. Thanks.

- Aaron

#1243209

Shane
Supporter

Languages: English (English )

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

Hi Aaron,

As Christian I on vacation for this week I will be handling this ticket for him.

I See that this has a long thread history since 2018 so it would be alot to go through.

Is this current issue related to any of the issue you've been experiencing since the start of the thread?

Please let me know.
Thanks,
Shane

#1244817

Hi Shane,

Maybe in the interest of time don't bother going through the entire thread. It seems to be the same problem but I'm not entirely sure if it's necessarily the same cause. If you just focus on the last message it might be enough since I've described all the relevant posts, snippets, etc. Thanks.

- Aaron

#1249701

Shane
Supporter

Languages: English (English )

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

Hi Aaron,

Tried having a look at this for you but noticed that the credentials that were provided aren't working .

Also the link from your previous message went to a 404.

Could you send the credentials once more ?

Thanks,
Shane

#1249747

Hi Shane,

The credentials you want to use are:

The URL I sent should work once you are logged in using those credentials. Thanks.

- Aaron