Skip Navigation

[Resolved] Recursive view

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

Last updated by Waqar 3 years, 9 months ago.

Assisted by: Waqar.

Author
Posts
#1684413

Hello, how are you?

Need help. kkkk ...

I created a CPT on my website, called "coaches". In it I put a field called "superior id" to be able to make this type of post be hierarchical.

Example:

Hierarchy Levels:
1 - Master
2 - Gold
3 - Silver
4 - Bronze

Created posts:
- 1 master
- 1.1 gold
- 1.1.1 silver
- 1.1.1.1 bronze
- 1.1.1.2 bronze
- 1.1.2 silver
- 1.1.2.1 bronze
- 1.1.2.2 bronze
- 1.2 gold
- 1.2.1 silver
- 1.2.1.1 bronze
- 1.2.1.2 bronze
- 1.2.2 silver
- 1.2.2.1 bronze
- 1.2.2.2 bronze

I created the view to be able to call these posts. This is a simple view, which only filters through the "superior id" field, and inside the loop item, displays the post name and calls the view again, passing the current post id as a filter, so that it can type a recursive function.

However the view works only to a certain extent.

She printed up to that point on the screen:
- 1 master
- 1.1 gold
- 1.1.1 silver
- 1.1.1.1 bronze

After the bronze, there is no more post below it and should print the rest of the tree, as above, but it does not execute. it looks like the view does not go back to the previous level to continue with the display.

How to solve this?

In fact, I don't even know if I can use iterative or recursive views with toolset.

I am waiting for a possible solution.

Thank you

#1684415
Capturar.PNG

image to better understand. the editor did not show the hierarchy correctly.

#1685237

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

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

If the view is set up correctly and the sample posts exist at all levels, it should be showing the complete tree output.

To troubleshoot this, I'll need to see how these posts and the view is set up in the admin area.

Can you please share temporary admin login details along with a page where this view can be seen?

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

regards,
Waqar

#1686937

Hello,

Any news?

I'm waiting

#1687067

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for sharing the admin access.

First, I apologize for the delay, as we had an unusually busy queue before the weekend.

Although the user name and password to access your website's admin area, didn't work, I was able to make this work on my test website.

Here are the steps:

1. For my "Coaches" post type, I added a numeric type custom field with slug "superior-id". I also set the field to save '0' as a default value, which will be used for the grandparent items, like "1 Master", "2 Master" etc.
( screenshot: hidden link )

For all other child items, this field will hold the post ID of the parent item.

2. Next, I created a post view named "Parent Coaches View", which would be used to show only the grandparent items.

The view was set to show "Coaches" posts, ordered by "Title" and with a query filter for the "superior-id" field where the value is equal to '0'.
( screenshot: hidden link )

In the loop in "Loop Editor" section, I included only the title:


[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<ul class="wpv-loop js-wpv-loop">
		<wpv-loop>
			<li>
				[wpv-post-title]
			</li>
		</wpv-loop>
	</ul>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

When inserted on a page, this view shows all the grandparent posts.
( screenshot: hidden link )

3. The next step was to create another post view "Child Coaches View", which would recursively show the child items of the grandparent items.

This view was also set to show "Coaches" posts, ordered by "Title" and with a query filter for the "superior-id" field where the value is equal to the value passed through shortcode attribute "parent".
( screenshot: hidden link )

In the "Loop Editor" section, I included the title and the shortcode for this same view, so that it can loop through all the levels down. That shortcode also included the ID of the current post in the loop, passed as the attribute "parent":


[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<ul class="wpv-loop js-wpv-loop">
		<wpv-loop>
			<li>
				[wpv-post-title]
				[wpv-view name="child-coaches-view" parent="[wpv-post-id]"]
			</li>
		</wpv-loop>
	</ul>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
	[/wpv-no-items-found]
[wpv-layout-end]

4. The last step was to include the shortcode of this child view in the loop of the parent view as well.
( screenshot: hidden link )

And here is the screenshot of the final output of these views from the front-end:
hidden link

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

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