Skip Navigation

[Resolved] Filter view to show parent posts where a users child posts are present

This support ticket is created 3 years, 5 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 15 replies, has 2 voices.

Last updated by aaronW-4 3 years, 5 months ago.

Assisted by: Raja Mohammed.

Author
Posts
#1837467

Tell us what you are trying to do?
Is there any way to filter a view to just show all the parent posts where a user has submitted a child post within?
So, if there is a parent post called "Trips" and a user submits a child post within "Trips" called "My trip", how do I just show "Trips" and no other types of parent posts?

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#1838637

Raja Mohammed
Supporter

Languages: English (English )

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

Hello there,

I think what you are trying to achieve is to display the sibling posts under the parent in which the user posted the content.
We have a detailed documentation on how to achieve this https://toolset.com/documentation/user-guides/views/displaying-brother-pages/ Kindly go through it let me know if there is anything else i can assist with.

Kind regards
Raja

#1839179

If I'm a user who has created child posts, I want to be able to see a list of parents posts where my child posts are present.

#1839565

Raja Mohammed
Supporter

Languages: English (English )

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

You can create a new view for the post type with Parent Post Query filter and choose No parent (return top-level elements) hidden link which will return only the posts which has no parent (obviously they are the top level parent posts).

Use the view where the child post is displayed.

Reference : https://toolset.com/documentation/user-guides/views/filtering-views-query-by-post-parent/#no-parent-return-top-level-elements

#1840097
view-example-01.jpg

The view wouldn't appear inside a child or parent post. It would act as a dashboard where the child post creator would be able to view a list of each parent post where they have contributed a child post. The attached images should help.

#1841105

Raja Mohammed
Supporter

Languages: English (English )

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

It is a tricky situation to understand, I checked with the team for possible solution as far as i see this can only be achieved with legacy views.

The idea is to create a view for the patent posts that checks the number of posts created by the user which is achieved using a separate view and with the help of wpv-conditionals, we can display the parent posts that has the child created by the user.

1) Create a View for the top level parent posts that queries the post type with Parent Post Query filter and No parent (return top-level elements)

2) Create a Separate View for the child posts, This outputs only the post count, (view name child-view)
[2.a] Here we need to Add Two Query filters
-------> In the Query filter Choose Post author and select the option "Post author is the same as the logged in user". This will query for all the post created by the user
--------> Add Another Query Filter Choose Post Parent and select the Option "parent is the current post in the loop."
[2.b] In the loop editor use the below code , Make sure it is added in single line without any spaces.

[wpv-layout-start][wpv-items-found]<!-- wpv-loop-start --><wpv-loop>[wpv-items-count]</wpv-loop><!-- wpv-loop-end -->[/wpv-items-found][wpv-no-items-found][wpv-items-count][/wpv-no-items-found][wpv-layout-end]

- The code returns only the post count based filter we selected in 2.a
- In the view above the output editor Select the option "Disable the wrapping DIV around the View

3) Now open the View created in Step 1 Here in the loop editor , Wrap the loop tempalate inside a conditional tag to check for number of items in the child view created in step 2.

<wpv-loop>
          [wpv-conditional if="( '[wpv-view name='child-view']' gte '1' )"]
			<li>[wpv-post-body view_template="loop-item-in-parent-page"]</li>
          [/wpv-conditional]
		</wpv-loop>

This will only out the parent posts if they have chid posts created by the user.

I hope this helps better,

Let me know if you need more assistance :

References:
https://toolset.com/documentation/user-guides/views/filtering-views-query-by-author/#post-author-is-the-same-as-the-logged-in-user
https://toolset.com/documentation/legacy-features/views-plugin/conditional-html-output-in-views/#conditions

#1841507

Okay. I set it up as instructed, but it is showing all of the parent posts in the view. I did a quick screen recording showing how I set the two views up. Maybe I didn't do it correctly:
hidden link

It seems like it's really close to working, it just isn't filtering the view to only show the parents where the user has a child present.

#1841543

Removing

[wpv-filter-meta-html]

Did not change anything. Still showing all parent posts.

#1841847

Raja Mohammed
Supporter

Languages: English (English )

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

Screenshot 2020-11-12 at 2.06.16 PM.jpg

I misunderstood the parent as the parent of the same post type., I have gone through the video it seems like you have a post relation ship with Contributors and Crowd. In this case please alter the Query filter in the child view as below

1) Remove the Parent Filter in the Child view
2) Add a New filter Select "post relationship or repeatable fields group"
3) In the filter Select the appropriate relationship in the dropdown and choose the option The current post in the loop and save

This should help. Also make sure there are no extra spaces in the loop and output editor

#1842317
Screen Shot 2020-11-12 at 9.34.06 AM.png

It still doesn't show the parent results. To test it, I placed the "child-view" inside of the parent post results and removed the condition to see if it shows the correct number of child posts within the particular parent post results. It is accurate. It shows the correct number of child posts. For some reason, the actual condition isn't recognizing these parent posts. You can see in the attached image that the child-view works great. The child-view count is in the top left of each block, but I just need the ones showing "1" to show.

Here is what I have in the loop editor of the parent level:

[wpv-layout-start]
    [wpv-items-found]
    <!-- wpv-loop-start -->
	<div class="container wpv-loop js-wpv-loop">
           [wpv-conditional if="( '[wpv-view name='child-view']' gte '1' )"]
	<wpv-loop wrap="3" pad="true">
		[wpv-item index=1]
		<div class="row ">
			<div class="col-md-4">[wpv-post-body view_template="loop-item-in-contributed-to-list-top-level"]</div>
		[wpv-item index=other]
			<div class="col-md-4">[wpv-post-body view_template="loop-item-in-contributed-to-list-top-level"]</div>
		[wpv-item index=3]
			<div class="col-md-4">[wpv-post-body view_template="loop-item-in-contributed-to-list-top-level"]</div>
		</div>
		[wpv-item index=pad]
			<div class="col-md-4"></div>
		[wpv-item index=pad-last]
			<div class="col-md-4"></div>
	</wpv-loop>
      [/wpv-conditional]
	</div>
	<!-- wpv-loop-end -->
	    [/wpv-items-found]
[wpv-layout-end]
#1842427

Raja Mohammed
Supporter

Languages: English (English )

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

It would be better if you can share temporary access to the site so that I can have a closer look . Also let me know the page where the view is added.

I am enabling private reply to securely share the information.

#1843005

Raja Mohammed
Supporter

Languages: English (English )

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

Screenshot 2020-11-13 at 12.26.31 PM.jpg

I see the issue you are using loop index to form the elements which is quite hard to manage with the conditionals if i change the contribution list top level view loop to more simpler structure with out the loop wrap this works fine.

[wpv-layout-start]
    [wpv-items-found]
    <!-- wpv-loop-start -->
   <div class="container wpv-loop js-wpv-loop">
	<wpv-loop  >
      <div class="row ">
     [wpv-conditional if="( '[wpv-view name='child-view']' eq '1' )"]
			<div class="col-md-4">[wpv-post-body view_template="loop-item-in-contributed-to-list-top-level"]</div>
      [/wpv-conditional]
          </div>
       </wpv-loop>
     </div>
	<!-- wpv-loop-end -->
	    [/wpv-items-found]
[wpv-layout-end]

However if you wish to use wrap and pad in the loop then you might need some custom code to keep track of the loop . Take for example when you use wrap and for the [wpv-loop index=1] you should out put the opening <div class="row"> , However if the condition that we set fails for the first index which mean the first parent does not have any children created by the user then then the conditional fails and the loop skips the firs index item and moves to second item which results in a situation there will be no opening row and the html is broken and the conditional will also fail to evaluate since the closing [/wpv-conditional] is also affected.

I hope you get the issue now. With the simple loop you can see the conditional working without any issue. for testing i have set one of the contibution to my user name.

#1843517

That's great! The functionality of being able to see only the parent posts is more important than the style. I will work around this solution. Thank you very much for your attention to this!

#1843539

One last thing, and there may not be a way to do this. I wanted to also use [wpv-found-count] to show the total number of parents posts within the condition, but it is detecting the total amount of parent posts outside of the condition. Also, my message within [wpv-no-items-found] isn't working because it is counting the parent posts outside of the condition... Is there an easy fix for this? To just detect the quantity within the condition?

#1845469

Raja Mohammed
Supporter

Languages: English (English )

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

If i understand this correctly you only need to display the count of the parent posts that has the child is that correct? In that case [wpv-found-count] and [wpv-no-items-found] will not help it will only render the actual count by the parent query the conditional that we check only display the parent that has child in it and doesn't affect the total count retired by the parent view.

You might have to use some custom function to filter out the total count and keep track of the actual number of parent posts based on the conditionals.
https://toolset.com/documentation/programmer-reference/displaying-custom-functions-with-views-and-using-them-in-conditional-logic/

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