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
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.
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
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
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
You can manually debug the PHP codes, line by line, like this:
Make sure it is a single "Targets" post ID,
And you can get the current "Targets" post ID like this:
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.
My issue is almost resolved now. Thank you!