Skip Navigation

[Resolved] Classic view to show complicated relationship CPT

This support ticket is created 3 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/Karachi (GMT+05:00)

This topic contains 6 replies, has 2 voices.

Last updated by Waqar 3 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#2234309

Dear Sir/Madam,

I have a learning platform, below are the custom post-relationship

Classes [*] << Classes Users >> Users [*]
Courses [0 .. 1] << Classes [*]

There are two custom User Roles: Teacher and Student.

When a new WP user registers, a custom post User will be created and assigned as the same author and also change the WP user to either Teacher or Student role.

I want to create a Views to list out all classes that belong to the WP user if he/she is a teacher or student. I can create a View to filter the CPT user by current login author and get the CPT user's post id. Although there is a relationship between the CPT class and the CPT user, how can I filter the CPT user whose id is the post id I got and filter the class?

I use the classic View.

#2234363

I try putting below condition in Loop Editor

          [wpv-conditional if="([wpv-post-id item="@class-user.child"] = [wpv-view name="cpt-user-by-login-author"] )"]
          <a href="/myclass/?cid=[wpv-post-id]">[wpv-post-title]</a> [wpv-view name="cpt-user-by-login-author"] <br/>
          [/wpv-conditional]

but not work, I am sure I can get value from shortcode [wpv-view name="cpt-user-by-login-author"] , below is the output of shortcode

[wpv-layout-start][wpv-items-found]<!-- wpv-loop-start --><wpv-loop>[wpv-post-id]</wpv-loop><!-- wpv-loop-end -->[/wpv-items-found][wpv-no-items-found]0[/wpv-no-items-found][wpv-layout-end]

and I do disable the wrapping DIV around the View.

If I add [wpv-view] in Setting > Front-end Content > Third-party shortcode arguments but not allowed.

Please help.

Best regards,

Kelvin.

#2234831

Hi Kelvin,

Thank you for contacting us and I'd be happy to assist.

To suggest the most efficient way to achieve this, I'll need to see exactly how this view is set up in the admin area.

Can you please share temporary admin login details, along with the link to the page with this view?

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

regards,
Waqar

#2235703

Dear Waqar,

I can query the class by content template related to the CPT user while the CPT user has the same author as the current login user.

I create a content template and assign this Usage as Users (this is the CPT Users) and insert the shortcode [wpv-view name="all-classes-by-cpt-user"] into its body content.

I can view it by accessing hidden link where xxx is the post slug of CPT Users but I want to embed the content template by providing the CPT User id like

[wpv-post-body view_template="content-template-for-cpt-user" id="[wpv-view name="cpt-user-by-login-author"]"]

but doesn't work.

I can correctly display all related classes by hidden link where 2 is the slug of the CPT User and post id is 315.

Best regards,

Kelvin.

#2235915

Thank you for sharing these details.

In your view "All Classes by CPT user", I changed the relationship query filter to "The post with ID set by the shortcode attribute: wpvrelatedto".
( screenshot: hidden link )

This allows us to provide the ID of the target user post, in the view's shortcode attribute.

Since this is not possible using the "Views" block, I added a "Fields and Text" block in the "Demo - List my classes" page and included the view's shortcode like this:


[wpv-view name="all-classes-by-cpt-user" wpvrelatedto="[wpv-view name='cpt-user-by-login-author']"]

Please note, how I've used the shortcode for the other view ( [wpv-view name='cpt-user-by-login-author'] ), to pass on the currently logged-in user's "user" post, in this view's "wpvrelatedto" attribute.

As a result, current user's related classes are showing correctly now.
( screenshot from demo user that you provided: hidden link )

#2236929

Dear Waqar,

I finally fixed my issue by using a custom shortcodes like

[wpv-post-body view_template="content-template-for-cpt-user" id=[curr_cpt_user_id] ]

and shortcode [curr_cpt_user_id] must be added to Third-party shortcode arguments.

Is it true I can't put [wpv-view ... ] as parameter to [wpv-post-body .....] ?

Best regards,

Kelvin

#2238233

Thanks for the update and glad that you've managed to make it work.

The use of the custom shortcode [curr_cpt_user_id] seems like a good alternative for using a view to get the current user's related CPT post ID.

> Is it true I can't put [wpv-view ... ] as parameter to [wpv-post-body .....] ?
- In my tests, I was able to use the view's shortcode to pass the target post's ID in the 'item' attribute of the "wpv-post-body" shortcode:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-body

For example:


[wpv-post-body view_template="test-ct" item="[wpv-view name='test-view']"]

Note: To make this work, you'll have to ensure that the view's shortcode is only returning the numeric post ID, without any empty lines or spaces.