Skip Navigation

[Resolved] Show Related Custom Post Types in User’s My Account Page

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

Problem: I have created a Subscribers post type as a proxy for Users so I can create relationships between Users and Favorites (another custom post type). I would like to display a User's Favorites posts on their My Account page.

Solution: Use the legacy Views editor to create a View of Subscriber posts filtered by post author, where the post author is the same as the current logged-in User. Use the "list with separators" loop style and output only the post ID. Create another View of Favorites posts filtered by the Subscribers-Favorites post relationship, set by a shortcode argument "wpvrelatedto". Use the Loop Wizard to design the Favorites output. Nest the shortcode of the Subscribers View inside the wpvrelatedto shortcode argument of the Favorites View, for example:

[wpv-view name="your-favorites-view" wpvrelatedto="[wpv-view name='your-subscriber-view']"]

Relevant Documentation:
https://toolset.com/documentation/legacy-features/views-plugin/how-to-create-custom-searches-and-relationships-for-users/

This support ticket is created 3 years, 9 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 2 replies, has 2 voices.

Last updated by garyN-2 3 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#2039919

Tell us what you are trying to do? I am trying to extend the functionality in your "My Accounts" type pages to show the related custom post types of that user. I have created a "Subscriber" Custom Post Type and created a custom field for Subscriber that includes the User ID of the author. Each Subscriber has multiple Favorites (Another custom post types with a Many to Many relationship). When the logged-in user goes to "My Account" page, he should see his favorites.

Is there any documentation that you are following? Multiple documentation topics on creating custom post type linked to user by Author ID. and
https://toolset.com/documentation/legacy-features/views-plugin/how-to-create-custom-searches-and-relationships-for-users/

Is there a similar example that we can see?

What is the link to your site?

#2040055
query-filter.png

I have created a "Subscriber" Custom Post Type and created a custom field for Subscriber that includes the User ID of the author.
Hi, this is a bit different from what is described in the documentation, so I want to be clear about your implementation. The documentation describes creating a custom post type like your "Subscriber" and setting the post author of that Subscriber post to be the current User. It does not mention or include a custom field set to store the User ID. To be clear, are you using this custom field instead of setting the post author to be the corresponding User, or in addition to setting the post author as the User?

Depending on the answer to that question, the process is slightly different. In either case, you need to be able to determine the post ID of the current User's Subscriber post. Once you know that post ID, you can set up a View of Favorite posts with a post relationship Query Filter, configured to respond to a shortcode attribute like "wpvrelatedto" (see query-filter.png). Then using Views shortcodes, you can display that View of Favorites in the My Account page, something like this:

[wpv-view name="your-favorites-view" wpvrelatedto="123"]

In this example code, your-favorites-view represents the slug or name of your Favorites View, and 123 represents the post ID of the current User's Subscriber post.

To get that post ID, you could use another View of the Subscriber post type, filtered to display the Subscriber post associated with the current logged-in User. It would be best to create this View using the legacy Views editor, because the output format is technically very specific and not easily produced by the Block Editor. To enable the legacy Views editor, go to Toolset > Settings > General and find the "Editing experience" setting. Choose the option that enables both the legacy editing and Blocks editing experiences. Then you can create a new View of the Subscriber post type in Toolset > Views.

If you've set the User as the post author as the documentation describes, you would add a Query Filter to filter by post author equal to the current logged-in User. If you have not set the post author, you would filter by the custom field you described that holds the User ID, and probably pass in the current User ID using another shortcode attribute.

In either case, use the Loop Wizard and select the "list with separators" format. In the loop, output only the post ID. Then you can nest this View shortcode inside the other View shortcode, like so:

[wpv-view name="your-favorites-view" wpvrelatedto="[wpv-view name='your-subscriber-view']"]

Now this nested structure is designed to filter the list of Favorites by post relationship associated with the current logged-in User's Subscriber post.

Another way to get the Subscriber post ID is to create a custom shortcode that returns the User's Subscriber post ID. If you're interested in exploring that option and you're comfortable writing PHP, I can assist. This process is pretty technical, so I'm here to help if you get stuck along the way or need additional information.

#2041661

My issue is resolved now. Thank you!