Skip Navigation

[Resolved] Create a View of Parents based on Child Posts

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

Last updated by Minesh 7 years ago.

Assisted by: Minesh.

Author
Posts
#509360

Needed to reopen a question that previously closed. How would I go about creating the following two VIEWs?

- There is a CPT called Vehicles with children called Vehicle Records. John Doe creates a Vehicle Post called "VW Rabbit." Then David Rogers (another author/user) creates a Vehicle Record for the "VW Rabbit" called "Oil Change." What I want to do is show a list of Vehicles that David Rogers has created Child Posts for. So essentially display an author-specific view of vehicles driven by the author meta data of the child posts.

- Similarly I want to create a view that shows all users that have created child posts for a particular vehicle. This view would live in the content template for the vehicle, so in our example the list would show John Doe and David Rogers.

I am simply getting confused with the conditional outputs and filters.

Thank you!

#509603

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I have just one query - is "David Rogers" will be a logged in user?

#510068

David Rogers will be a registered user with author permissions. I want to display the view regardless of who the person looking at it is and regardless of their status as a logged-in or non-logged-in user.

#510101

Minesh
Supporter

Languages: English (English )

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

Actually - where you want to display the view - on author profile page? if not then what exactly will be the flow.

For example - you have one page where all user listed - when you click on any particular user name, it will redirect you on another page where we should display list of child post created by this user?

It will be great if you share test case or screenshot with above details.

#512234

Apologies Minesh for the delay. I would need to display this in the author profile page (we are using BuddyPress for this and already know how to insert the views into the profile page). So the real issue we have is creating the view. Below is a refinement on the best example I can write up for our desired output:

- There is a CPT called Vehicles with children called Vehicle Records. John Doe creates a Vehicle Post called "VW Rabbit." Then David Rogers (another author/user) creates a Vehicle Record for the "VW Rabbit" called "Oil Change." What I want to do is show a list of Vehicles that David Rogers has created Child Posts for. So essentially display an author-specific view of vehicles driven by the author meta data of the child posts. So in David Rogers' author profile page we would see the VW Rabbit listed because he created a vehicle record (child post) for that vehicle.

Not sure if it helps, but would using a dropdown select custom field assist with this? My thinking here is that maybe we could filter a view by a custom field so that it only shows in the author profile page if the person created a vehicle record (child post) for the vehicle (parent post) and selected a specific value in the custom field dropdown (i.e. Current Owner, Previous Owner).

One concern that we have is that using the child posts to drive the view would result in a vehicle (parent post) being listed multiple times (once for every child post). What we're actually hoping to achieve is a view that only shows each specific vehicle once. Is there a way to limit the results if a result (specific vehicle) has already been returned in the view?

#512566

Minesh
Supporter

Languages: English (English )

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

- There is a CPT called Vehicles with children called Vehicle Records. John Doe creates a Vehicle Post called "VW Rabbit." Then David Rogers (another author/user) creates a Vehicle Record for the "VW Rabbit" called "Oil Change." What I want to do is show a list of Vehicles that David Rogers has created Child Posts for. So essentially display an author-specific view of vehicles driven by the author meta data of the child posts. So in David Rogers' author profile page we would see the VW Rabbit listed because he created a vehicle record (child post) for that vehicle.
===>
This is possible.

If you are on user profile page, you will get author ID using the function get_queried_object_id()

You need to create two views here - one for your parent post type (Vehicles ) and one view for child post type (Vehicle Records). Please check following steps.
1) Create view namely "parent-view-Vehicles"
2) Create another view namely "child-view-Vehicle-Records"
2-a)
- Add query filter to view - Post relationship filter:

Select posts that are children of the Post with ID set by the shortcode attribute wpvprchildof.
eg. [wpv-view name="view-name" wpvprchildof="123"]

- Add query filter - filter by author:

Post author filter
Select posts which author's id is set by the View shortcode attribute "author" eg. [wpv-view name="view-name" author="1"]

2-b) Navigate to "loop output editor" and add shortcode:

[wpv-post-title id="$vehicle"]

3) Add child view "child-view-Vehicle-Records" to your parent view "parent-view-Vehicles" loop output editor section.

[wpv-view name="child-view-Vehicle-Records" wpvprchildof="[wpv-post-id]" author="[wpv-current-user info='id']"]

Then - as you are using PHP template to dispaly the author info. You can use views API to dispaly the above views with your PHP author.php template file:
=> https://toolset.com/documentation/user-guides/views-api/
=> https://toolset.com/documentation/user-guides/filtering-views-query-by-author/

So - using views API you can add view to your PHP template file. For example:

$args = array(
    'id'=>9999,
    );
    echo render_view( $args );

Where:
- Replace 9999 with your view ID. In your case - your parent view id.

We have complete guidance available with our Docs about creating user profiles:
=> https://toolset.com/documentation/customizing-sites-using-php/creating-custom-user-profiles/

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