Skip Navigation

[Resolved] Post relationship parent is populated with 0 (zero) when editing with CRED

This thread is resolved. Here is a description of the problem and solution.

Problem: When editing a child post with CRED, if I deselect the parent post and submit the form I can see that _wpcf_belongs_parentslug_id = 0 in the database. However, if I perform the same change in wp-admin, _wpcf_belongs_parentslug_id is completely deleted for this post. I have a conditional set up that tests whether or not the _wpcf_belongs_parentslug_id field exists, and it's failing because 0 is not the same as not exists.

Solution: For now, it's probably best to work around this discrepancy because relationships are changing in the very near future.

$clientprocess_id = get_post_meta( $quest_id, '_wpcf_belongs_clientprocess_id', true);
if (isset($clientprocess_id) && $clientprocess_id > 0)...
This support ticket is created 6 years, 8 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by KenG8581 6 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#693196

Hi
I have CPT called Actionitem. It has three parents (Actionplan, Process and Clientprocess).
Parent Actionplan is mandatory, while Process and Clientprocess is an either/or. Either Actionitem has parent Process or parent Clientprocess.

I create the Actionitems in my plugin, I assign an Actionplan (_wpcf_belongs_actionplan_id) and either a Process (_wpcf_belongs_process_id) or Clientprocess (wpcf_belongs_clientprocess_id), and everything looks fine and works as designed.

However, when I edit an Actionitem for eg. child of a Process in a CRED form and save it (only updating Actionitem fields and not relationships), the wpcf_belongs_clientprocess_id is created on the Actionitem with a value of 0 (zero). And opposite if editing an Actionitem for child of Clientprocess.

Is that intentional and per design? I havent seen this behavior before as Toolset normally doesnt store 'empty' values.

#694394

I see what you mean, if you edit a post with CRED the parent references are set to 0 but if you edit the post in wp-admin the behavior is different. I can reach out to the team to find out if this is on purpose or not, but to be honest relationship references are changing very soon in the M2M release, and I doubt changing the current behavior will be a top priority. Is this 0 causing a problem for you somehow? It might be more practical to work around that problem than to wait for a modification here.

#695983

Hi Christian
Thanks for you quick and clear response - once again 🙂
I fully understand and support the prioritization of the M2M release, and I will make the necessary changes to work around the 'uneven' behavior.
You bring up another important point for us as developers. Is there any documentation that we can read to understand the changes coming, and how it may impact our own coding and use of Toolset API?
Best
Ken

#696789

... and ...

In Toolset View, until today, I used this conditional check:

[wpv-conditional if="((!empty($(_wpcf_belongs_clientprocess_id))))"][wpv-post-title id="$clientprocess"][/wpv-conditional]

That is have now changed to:

[wpv-conditional if="( $(_wpcf_belongs_clientprocess_id) gt '0' )"][wpv-post-title id="$clientprocess"][/wpv-conditional]

So far I have been using (in PHP):

$clientprocess_id = get_post_meta( $quest_id, '_wpcf_belongs_clientprocess_id', true);
if (isset($clientprocess_id)) ...

Can you guide me as to how I safely should check for the presence of the parent in both Views and PHP?

#710465

You can change the conditional in PHP like so:

$clientprocess_id = get_post_meta( $quest_id, '_wpcf_belongs_clientprocess_id', true);
if (isset($clientprocess_id) && $clientprocess_id > 0) ...
#743692

Thanks Christian