Skip Navigation

[Resolved] Relationship results does not work on CRED Forms

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

Problem:

make a new post form (child object) and i want in that form to be able to connect with a parent post (one to many rel.)

Solution:

So it is your custom JS codes errors prevent Toolset form from working, I suggest you debug your codes manually, or you can remove them and test again.

Relevant Documentation:

This support ticket is created 6 years, 2 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: Asia/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by kostasO 6 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#1166866

I am trying to:
make a new post form (child object) and i want in that form to be able to connect with a parent post (one to many rel.)

Link to a page where the issue can be seen:
hidden link
I expected to see:
a list box with the relationship results (the albums of the user)
Instead, I got:
an empty list box

i have tried the relationship to a view and it workd fine. only it CRED i have the issue.
alse have read all the related tuts of your site

#1167402
js-error.JPG

Hi,

Thanks for the details, I have tried the URL you mentioned above, but get some JS errors, for example:
Uncaught TypeError: Cannot read property 'split' of undefined

Then I have checked the form (ID 50) in your website:
hidden link

section "Content", click tab "JS Editor", there are some custom JS codes, you can try to remove them and test again, it works fine, see screenshot js-error.JPG

So it is your custom JS codes errors prevent Toolset form from working, I suggest you debug your codes manually, or you can remove them and test again.

#1167452

Good morning Luo

Thank you for your answer it works now. I wanted to ask you something else. basicaly i upgrade my site to the new version of toolset. in the previews version I was using that Java code to get the relationship in custom php code .
inise that code i was using the
$catid = get_post_meta($post_id,"_wpcf_belongs_target-collection_id",true);
to get the name of the list box of the cred presenting the selected result of that relationship.

now it does now work that

i see inside cred that the relationship variable is @target-collection-target.parent

how can i read now this value ?

thanks

#1167464

Yes, you are right, in the new post type relationship of Types plugin, you can get the parent post information with new API function toolset_get_related_post(),
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

for example: in a single child "Targets" post, you can get the related parent "target-collection" post's ID, like this:

$target_collection_id = toolset_get_related_post( $post_id, 'target-collection-target' );

The slug "target-collection-target" is your relationship slug:
hidden link

#1167499

It seems that i have not understood something...

as i have read at the documentation
if a use the command
$target_collection_id = toolset_get_related_post( $post_id, 'target-collection-target' );

i will get the ID of the selected parent for that specific post

and after that logically with the command
$catname = get_the_title($target_collection_id );

i will get the value that was displayed inside the list box

is this correct ?

because i use the snippet
$target_collection_id = toolset_get_related_post( $post_id, 'target-collection-target' );
$catname = get_the_title($target_collection_id );

$newpath = $uploads['basedir']."/$catname";

if(!file_exists($newpath)){
mkdir($newpath, 0777, true);
}

and it seems that i cannot get that value of the list box

#1167519

You can manually debug the PHP codes, line by line, like this:

echo $post_id;

Make sure it is a single "Targets" post ID,
And you can get the current "Targets" post ID like this:

$post_id = get_the_ID(); 

Then use the var $post_id in your custom PHP codes, more help:
https://developer.wordpress.org/reference/functions/get_the_ID/

If you still need assistance for it, since the original question of this thread is resolved, please create new ticket for the new question, that will help other users to find the answers.

#1170594

My issue is almost resolved now. Thank you!