Skip Navigation

[Resolved] Create view to display child posts

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

Problem:
How to create view to display related child post using nested view and display parent post custom fields.

Solution:
In this case, You can find proposed solution with the following reply:
=> https://toolset.com/forums/topic/create-view-to-display-child-posts/#post-600438

Relevant Documentation:
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

This support ticket is created 6 years, 11 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.

Our next available supporter will start replying to tickets in about 8.79 hours from now. 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 18 replies, has 2 voices.

Last updated by marcB-6 6 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#600088

I have created custom post type called "Quotes".
I have around 50 other custom post types like : Restaurants, Watersports , Bars , Nature etc...
I have assigned custom post type "Quotes" as Children Post Types to other custom post types mentioned above.
Now, I have added posts to custom post type and for each post I am adding quotes.
I have detail page for each post added in : Restaurants, Watersports , Bars , Nature..In that page I would like to display quotes added to particular post in slider which is working fine with view I have created with query filter "Post where this View is shown".

I would like to display post Image and title as well for which I have added quote..
To achieve that I have put something like this :

<h4>[wpv-post-title id="$parent"]</h4>
<span>[types field='area-name' output='raw' id="$parent"][/types]</span>

But, It is not giving me post title and the field value of area-name of post in detail page.
Instead, It is giving me title of quote.

Example,
Custom Post Type : Restaurants
Post Added : Indian
Quote added to post "Indian" : Best Restaurant

Now, On detail page of post "Indian" I would like to show "Best Restaurant" in slider which is working fine.
But, To display post title "Indian" in slider I wrote [wpv-post-title id="$parent"] which is not working and returning the title "Best Restaurant" Instead of "Indian".
If I write [wpv-post-title id="$restaurant"] it is giving me title "Indian" but then I need to create multiple view for each post type which is not correct.

#600134

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - to display the parent post information, you need to use your parent post type slug.

For example, for instance you have custom post type "Student" and the slug for this post type is student :

<h4>[wpv-post-title id="$student"]</h4>
<span>[types field='area-name' output='raw' id="$student"][/types]</span>

- please replace "student" with your original parent post type slug.

More info:
=> https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

#600149

Ok Thanks.
it worked for me by below code

<h4>[wpv-post-title id="$current_page"]</h4>

The same view I am calling view like this
[wpv-view name="quote-slider-overview-page" wpvprchildof="$restaurant"]
Now, if I put condition in my view something like this

[wpv-conditional if="('[wpv-post-taxonomy type='location-type' format='slug' id='[wpv-attribute name='wpvprchildof']']' ne '' )"]
                <span class="slider-tag">[wpv-post-taxonomy type="location-type" format="name" id="[wpv-attribute name='wpvprchildof']"]</span>
                [/wpv-conditional]

It is not working.

This is working ---> [wpv-post-title id="[wpv-attribute name='wpvprchildof']"] returns title
This one is not ----> [ratings id="[wpv-post-id id='[wpv-attribute name='wpvprchildof']']" results="true"]

#600159

Minesh
Supporter

Languages: English (English )

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

Welll - you are using wrong code:
[wpv-view name="quote-slider-overview-page" wpvprchildof="$restaurant"]

Above code should be:

[wpv-view name="quote-slider-overview-page" wpvprchildof="[wpv-post-id id='$restaurant']"]
#600164
Screenshot_5.png

Above shortcode is not returning results.
see attached screenshot for view filter.

I would like to get child posts of specific post type that is why i have wrote it like this

[wpv-view name="quote-slider-overview-page" wpvprchildof="$restaurant"]

It is working and giving me results as well.
Below code returns proper data

<h4>[wpv-post-title id="[wpv-attribute name='wpvprchildof']"]</h4>
             <span>[types field='area-name' output='raw' id="[wpv-attribute name='wpvprchildof']"][/types]</span>
#600167

Minesh
Supporter

Languages: English (English )

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

Well - that is wrong syntax even though you are using it 🙂 and not the suggested way even though you are having results. However - I'm surprised that how its displaying the results.

You must have added your view to parent or whatever.

Please let me know for which post you want to display the child posts, and send me access I need to check and correct the things so the buggy syntax you are using should not effect you in future.

*** 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.

#600188

Minesh
Supporter

Languages: English (English )

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

Ok - I checked on your install and I see that you've added the view on your parent post. So, the correct code will be as follows:

[wpv-view name="quote-slider-overview-page" wpvprchildof="[wpv-post-id]"]

As you are already on parent post id - you need to use [wpv-post-id] to get post id.

#600190
Screenshot_6.png

Hi Minesh,

As you can see in the page I have given..That is for restaurant so on that page I would like to display quotes from all posts which are added in 'restaurant' post type...

I see slider is screwed up..It is not working as it was before..
It is not displaying image,taxonomies name and other stuff.

#600202

Minesh
Supporter

Languages: English (English )

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

Sorry - there must be something wrong what you try to explain me or I didnt understand what you are looking for.

You want to display all quotes that belongs to any restaurant post(s)? I do not able to see CPT quotes or restaurant in backend, did you hide it?

#600209
Screenshot_7.png

You want to display all quotes that belongs to any restaurant post(s)? I do not able to see CPT quotes or restaurant in backend, did you hide it?

Ans : yes, it is inside eating & drinking > resturants and quotes is set child post of resturants

On this page : hidden link
I want to display all quotes that belongs to any watersport post(s).quotes is set child post of watersport.
At the moment it is displaying quotes from all post types..but it should display only from watersport posts.

Please check attached screenshot

#600218

Minesh
Supporter

Languages: English (English )

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

Sorry - you are mixing two requirements here.

On this page : hidden link
I want to display all quotes that belongs to any watersport post(s).quotes is set child post of watersport.
At the moment it is displaying quotes from all post types..but it should display only from watersport posts.
==> Is this another requirement?
==> Does this page using same view as you are displaying quotes under slider?

in order to avoid any confusion, please give me both problem urls and view's its using separately so I can think of the solution.

#600224

==> Does this page using same view as you are displaying quotes under slider?
Yes Minesh..
I have an overview pages for resturant,watersport which is displaying posts from resturant and watersport respectively.

Now, for each post in resturant,resturant I am adding quotes.
Restautrants : hidden link
Water Sports : hidden link

My requirement is to get all quotes from Resturants posts on this page : hidden link with Resturants post name,image,taxonomy title(ie:zanzibar)

And get all quotes from Watersports posts on this page : hidden link with Resturants post name,image,taxonomy title(ie:kiteboarding on bonaire)

I am not sure if it is possible with single view..Or we can pass an argument to a view.
If its possible with single view then I will directly call that view from content template.
if we are going to pass an argument then I will add it to the custom field editor and I will use that field to get view shortcode.

Please let me know if you have any confusion.

#600226

If you see both pages
hidden link
hidden link

It is displaying same date, Instead of that
hidden link
Should display 2 quotes
1)nice place & 2) Blue quote..because they are from restaurant post
hidden link
Should display 1 quote
1)Kite..because they are from watersport post

#600438

Minesh
Supporter

Languages: English (English )

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

Well - for such structure it needs nested view in order to loop through all parent (restaurant) and get their child posts (quotes) and display it.

I've created this view for parent (restaurant):
=> hidden link
- check loop output section (I've added child view that display quotes to this view)

I've adjusted the parent using $restaurant instead of [wpv-attribute] shortcode to all your shortcdoes used inside the child view (quotes):
=> hidden link
- check loop output editor section
- check query filter section

I can see that its displaying only two quotes now on this page:
=> hidden link

The same way you need to create parent view for "watersport" and add child view to display quotes.

#600443

I see on this page : => hidden link it is adding blank slide in slider.
There are 2 quotes in restaurants then why it is adding 3 slides including blank slide?