Skip Navigation

[Gelöst] How to Create post relationship between custom post types

This support ticket is created vor 6 Jahre, 9 Monate. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 33 Antworten, has 2 Stimmen.

Last updated by Minesh vor 6 Jahre, 9 Monate.

Assisted by: Minesh.

Author
Artikel
#536599

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thank you for choosing Toolset.

Now i would like to filter the view for custom_id variable and check it if it is equal to logged user in query filters i see only author or if i select this custom id i can not make it equal to logged user constant as there is no such constant to choose from

is there some tutorial or maybe you can give me a hint?

#536600

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - to filter your posts by logged in user ID and compare the logged in user ID with custom field value there are two ways:

First option:
- Create a view and set your post type
- Add Query Filter - for your custom user field and select filter by shortcode attribute :

Select posts with custom field: userid is a string equal to VIEW_PARAM(userid)    

- Insert the View in a Page and pass the shortcode parameter to display only posts with Custom Field equal to currently logged in user.

For Example:

[wpv-view name="your-view-name" userid="[wpv-user field="ID"]"]

More info:
=> https://toolset.com/documentation/user-guides/passing-arguments-to-views/
[Section: "Controlling the filter with shortcode attributes"]

Second option:
- Using [wpv-conditional] shortcode in loop output
For example:

[wpv-conditional if="( $(wpcf-your-field) eq '[wpv-user field="ID"]' )"]
What you want to display here
[/wpv-conditional]

More info:
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
=> https://toolset.com/documentation/toolset-training-course/part-6-conditional-output/

Please let me know if you need further infos about this and let me know if the above solution works for you, I look forward to your reply!

#537858

I am a little bit confused about views and content layouts..

I have Such relationship : User Diet is parent to Harmonogram. Diet Day is also parent to harmonogram. So in User Diet i can choose diet days using harmonogram connector and save. So i can create different user diets with the same Diet days:)

Now in User diet content template i would like to get Diet days fields not only harmonogram.. no i can get only Harmonogram using loop how to insert

In diet template insert harmonogram loop (filtered by diet parent) and nested fields from diet day which is parent to given harmonogram.

#538430

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - we have FAQ page that might help you to resolve your doubts between views and content template:
=> https://toolset.com/faq/whats-the-difference-between-a-view-and-a-view-template/

You can use views to display content list and even you can filter the data and you can use the content template to display the content with custom fields + views etc..etc..

We have a complete guide available about how you can display related content:

- To display child posts:
=> https://toolset.com/documentation/user-guides/displaying-related-child-posts/

- To display Brother pages:
=> https://toolset.com/documentation/user-guides/displaying-brother-pages/

- To display fields of parent post:
=> https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

- To display grandparent content:
=> https://toolset.com/documentation/user-guides/displaying-fields-grandparents/

If you still have issues, I need problem URL and one test case example what content you would like to display and where.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#538519

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

As I understand you would like to build custom user profile pages and only logged in user can see his profile and if logged in user try to access another user profile by editing the URL param you want to redirect user to another page (home page ) or he should remain on his profile page - correct? Could you please confirm.

If above scenario is correct then - we offer detailed tutorial how you can build custom user profile pages.
=> https://toolset.com/documentation/customizing-sites-using-php/creating-custom-user-profiles/

#538528

The difference is the user is not creating posts by himself - admin creates diet (posttype) and assign user id to it:). I thought in the begining that admin can change "author" field it would be the easiest but i think it is impossible ? Thats why you suggested me a custom ID in post then restrict content using the code you mention but it doesnt restrict links..

#538531

Is this possible to change author of a custompostype? Then i wouldnt need the custom id field etc just create the diet for a client who registered with woocommerce as admin and in the end of edition change the author of this diet and in front i would make author page for his diets:) i hope you understand what i mean:)

Now when someone buy a product he is a client role not an author so i can not choose him on an edit page of a post:( do woocommerce clients can become authors?

The other thing is authors can delete their posts...and o would like to create a post as admin for user. User has his diet page to see diet for him but do not let him delete it

#538548

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've reopened this ticket as I think you still need assistance with your issue and you may be marked it resolved by mistake.

Now - to display any users with your post author meta box you can use following code. Add following code to your current theme's functions.php file.

add_filter('wp_dropdown_users_args', 'assign_any_users_func', 10, 2);
 
function assign_any_users_func($query_args, $r){
    $query_arg['who'] = 'any';
    return $query_arg;
}

This will dispaly 'any' (all) user with author dropdown.

More help:
https://developer.wordpress.org/reference/functions/post_author_meta_box/

#538700

ok i will try that and then what

i create layout for each postype and filter by author and it is enough to secure links and urls not to enter by no authors ?

#538719

i think i have still something wrong in filter by author in views as when i click preview as administrator i can see diet which is assigned to another user as author?

I have relation diet is parent of harmonogram
diet day is parent of harmonogram
in diet i choose diet days using harmonogram connector how should i set author filters ?
Is author set automatically to connector post type

#538759

I think i know what can be the problem when i create diet i choose author and then i add days created earloer using connector in the diet editor panel but i think (days or harmonograms are still created by admin) how can i set the same author for child posts created) i checked it by inserting post_author_field into the loop
i found this

https://toolset.com/forums/topic/how-to-automatically-change-the-child-author-when-parent-author-changes/

but i want to do it in admin panel

#538899

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

You need to give me exact requirements so that I can guide you in right direction.

Please note that views work on the front end, not in the backend (admin).

Now - As I understand you want to assign parent post author to all related child posts that mean parent post author is same as child post author?

#539013
views.jpg
view2.jpg

I attached some screens below are two links one diet is assigned to admin and the other to test test user.

In admin panel in test user diet edit i choose diet day each time creating new harmonogram connector.

On archive pages it is ok i set view to display diets with author filter so if i enter as admin i see admin as test i see test but when i go futher to single diet page where i created view with child items (connectors) i can both see admin and test user harmonogram items both links can be opened by both users it is because when we create in diet edit screen new item it is created as admin even if parent is set to test test .

So my question is how to secure child items where parent item is assigned to given user?Thats why i asked if it is possible to set child author as parent but maybe you know other way to secure child items and they dont have to be the same author?

I am using many to many relationship and i would like to admin see only his posts and his child posts and test test user to see only his post with his child posts and so on with any user:). Or if it is possible admin can see all user posts and normal (authors ) only their posts with child items

hidden link
hidden link

Maybe i can send you credentials ?

#539018

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - would be great if you can send me access details and problem URLs.

Please send me both user accounts admin and test access details for which you assigned one post to each user.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#539551

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thank you for sharing access details.

I see your post types: "Dni diety" - "Diety użytkowników" - "Harmonogramy"

I also see that post types "Dni diety" and "Diety użytkowników" is setup as parent for post type "Harmonogramy". But I see strange thing that I do not able to see post type "Harmonogramy" on admin menu. Where I can see connected "Harmonogramy" and author?

I only see related posts with "Dni diety" and "Diety użytkowników" when I edit the post - i do not see any relation with post type "Harmonogramy":
=> hidden link

Also - Your login details for test account is not working. I see you are trying to use the view to display the posts.

I have set the next reply to private which means only you and I have access to it.

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