Skip Navigation

[Resolved] View of child of parent in another child of same parent

This support ticket is created 6 years, 4 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 15 replies, has 2 voices.

Last updated by Ljuba 6 years, 3 months ago.

Assisted by: Nigel.

Author
Posts
#958003
s-001.png
c-003.png
c-002.png
c-001.png

==> I am trying to:

I think that I have same problem with two different situations (as one is child post and second is RFG - what is basically same, but also - one is pure fields and second have field/taxonomy mix).

1) Simple case is where I in 'Accommodations' CPT parent post - 'Business', created RFG for Payment Gateways fields. I created the View as it is in documentation (image c-001 - P.S. - I have same also if it is set 'All') and I have fine display in 'Business' CPT single.php (image c-002, red rectangle). But in 'Accommodations' CPT I have error (image c-003, red rectangle), or better to say, nothing is found.

I'm obviously doing something wrong, but no idea what.

P.S. I tried also to create another View for 'Accommodations' CPT where I loop previous View, but same outcome.

2) Probably more complicated, but essentially same issue. As in this case I needed taxonomies, I created 'Follow Us' child post of 'Business' CPT. That 'Business' CPT should to be displayed in its own 'Accommodation' child post (and mainly all works fine). Obviously, all are in 'one to many' relationship.

Here I created single taxonomy view to display and loop social networks icons like 'termmeta'. Post itself contain only 'links' field. So, I have same single post view as above (same settings) amd in Content Template (for loop) I have:

<a href="[types field='enlace-de-red-social' raw='true'][/types]" target="_blank">[wpv-view name="taxonomy-single-view-de-siguenos"]</a>

Taxonomies are displayed fine (Image s-001, red rectangle), but links lead me in ALL ICONS to the same, present/current Accommodation post itself.

As it is about the fields, I think that case is same.

So, please, what I set wrong?

#958739

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Ljuba

I'm looking at the first of these on your site and I'm not sure I can see the issue.

When looking at the Hostal Bumba negocio post I can see some PayU and Paypal logos for payment options, and then in the Politicas y Condiciones section I can see data for the "Pasarelas de pago soportadas" entry.

When looking at the Hostal Bumba alojamiento post, I don't see the PayU and Paypal logos but I don't see any "No items found" message either. The Pasarelas de pago soportadas data is correctly displayed.

Did you change something in the Alojamientos template?

Is the intention that you should be able to see the same on the alojamientos post as the negocios post?

#958759
003.png
002.png
001.png

1) Negocio single.php is in stage of 'working mess' (so, it's work, but it will not look at ll as it is).. Briefly, it works for purpose to insert and control shortcodes display (what I did with "View para Checkear ahora" - I iserted only for purpose to see is it working in its 'native' post - and it working - images 001 and 002).

2) Negocios page from main menu will be in fact sort of extended Negocios Archives page for business and not real single.php (in other words, there will not be single.php for it).

3) In Alojamiento is still error (see actual screenshot 003). You simply should to click on 'Checkear ahora' to 'unfold/colpse panel.

#1069279

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Ljuba

Looking at the alojamiento single posts, you have an Elementor template for alojamientos which includes the Views content template "plantilla-de-encabezado-de-alojamientos" which includes the View "post-single-view-para-checkear-ahora".

When I look at that View I see that it is set to display alojamientos posts with a Query Filter to display posts in any relationship related to the current post in the loop.

But that doesn't make sense.

You are already on a single alojamiento post, I don't think you expect to find other alojamiento posts that are related to the current one.

The output of this View is another View "View para Checkear ahora", which outputs the repeatable field groups "Grupo de servicios de pasarela de pago".

But that repeatable field group belongs to negocios, not alojamientos.

If you are looking at a single alojamiento post and want to display repeatable field groups of a parent negocio then you should have your View that displays repeatable field groups belonging to the "current" negocio, insert that inside an unassigned Content Template, then insert that content template into your alojamientos template, specifying in post selection that the source post should be the parent from the negocios-alojamientos relationship.

Does that make sense?

#1069584
001.png

I'm confused (I'm doing something wrong? - looks like).

1a) I followed https://toolset.com/documentation/getting-started-with-toolset/creating-and-displaying-repeatable-field-groups/#displaying-repeatable-field-groups

1b) I have simplified one field "View para Checkear ahora" (view just for purpose for RFG display in 3 columns) with filter "Select items from the Grupo de servicios de pasarela de pago group that are related to the Post where this View is shown." ("Select posts in Any relationship that are related to the Post where this View is shown." show the same output) ("Don't include current page in query result" - unchecked/checked - same output - now is checked as on the tutorial). I think that it should to be fine.

2) Than I created (as you wrote) for parent "Negocio" post type view - "Post Negocio Single View para Checkear ahora" with filter "Select posts in Any relationship that are a related to the current post in the loop." and ("Don't include current page in query result") - unchecked.

I inserted that View in Negocio single.php (controled by Elementor) and it is displayed correctly.

3) Than i created unasigned Content Template - "Plantilla de checkear para alojamientos" and inserted "Post Negocio Single View para Checkear ahora".

[wpv-view name="post-negocio-single-view-para-checkear-ahora"]

4) Finally, following you and https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#using-views-only, I inserted in Elementor Alojamiento shortcode widget (see image)

[wpv-post-body view_template="plantilla-de-checkear-para-alojamientos" item="@negocio-alojamiento.parent"]

... and "No items found". I tried also to replace item="@negocio-alojamiento.parent" with item="@negocio.parent" and - same (worse - blank).

#1069967
001.png

Maybe you will better understand my confusion if you pay attention on fact that I have basically 100% same situation on post, but successfully displayed (see image).

So, Legal pages is child post of Negocios (what should to be sme as RFG - right?) and I displayed 2 Legal Pages (2 child posts) on Alojamientos. I placed

[wpv-post-body view_template="plantilla-para-paginas-legales"]

in View for Legal pages and than that Legal Pages View placed directly in Negico View

[wpv-view name="post-single-view-de-paginas-legales"]

Finally, that Negocio View I placed in Elementor Alojamiento single.php template

[wpv-view name="post-view-de-informaciones-legales-del-negocio"]

So please do not be surprised at why I'm completely confused ("lost").

#1070316

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You have the following structure

       negocios
       /      \
      /        \
    RFG      alojamientos

The RFG is a child of negocios.

So when you display a single negocio post (e.g. the Hostal Bumba negocio), to display the RFG fields you insert a View that displays the RFGs (with a Query Filter to set the "parent") directly into the single negocio template. One View.

When you want to display the RFG on an alojamientos single post (e.g. the Hostal Bumba alojamiento), you use the same View, but you need to place it in the context of the parent negocio, which you can do by inserting it into a Views Content Template (unassigned). That template is simply a container for the View to set the context of the parent negocio. So in this case we have one View and one Content Template.

You then need to insert that Content Template into the template for single alojamiento posts. You should use the Field and Views button when you do and use the Post selection tab to set the relationship, i.e. you want the parent from the negocios-alojamientos relationship.

In your description above it sounds like you have too many Views (there is only one in my description here).

#1070317

1) I agree how it looks like too much, but it works (for Legal pages).

2) You repeated reply (steps). I already replied (https://toolset.com/forums/topic/view-of-child-of-parent-in-another-child-of-same-parent/#post-1069584) and you can see what I did (also images). I can't see nothing wrong, but it simply not working (THAT'S THE FACT).

Now, what I should to do (as I already did how you explained - but it not working)?

#1071347

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

"I already did how you explained". No, you have too many Views, which is why I repeated the steps.

I'm just trying to edit your site directly, but the template for Alojamientos is locked because you are editing it.

I'll try again soon.

#1071356

Yes. I played tonight around it (not anymore). I also changed thinks and followed link:

https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-related-child-posts/

BUT IT NOT WORKS AGAIN.

Now schema is

negocios
/ \
/ \
RFG alojamientos

Plantilla de Negocios para Chequear ahora (PARENT > plantilla-de-negocios-para-chequear-ahora)

[wpv-view name="listado-de-pasarelas-de-pago-para-chequear-ahora"]

Plantilla de Alojamientos para Chequear ahora (CHILD > plantilla-de-alojamientos-para-chequear-ahora)

[wpv-post-body item="@negocio-alojamiento.parent" view_template="plantilla-de-negocios-para-chequear-ahora"]

Listado de Pasarelas de pago para Chequear ahora (CHILD of Alojamiento) - View that lists all children of a parent post - SLUG - listado-de-pasarelas-de-pago-para-chequear-ahora

View de RFG para Checkear ahora - SLUG - view-de-rfg-para-checkear-ahora

1) So, nothing is there from before.
2) You can delete also this (if you need)
3) As far as I can see is that I cannot assign Content Template to Alojamientos as it is now controled by Elementor.

#1071420

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I had to make one change for this to work.

Note that I edited the Elementor templates for both negocios and alojamientos and inserted a shortcode module just above where you have the offers section (see screenshot).

You already have a View I could use, "View de RFG para chequear ahora".

For the negocio template, I simply inserted that View directly into the shortcode module. (I could have used the Views widget module, but ¯\\_(ツ)_/¯ )

When I look at a negocio post, that View shows its child RFGs.

Now for alojamientos.

I want to insert the same View, but I'm not on a negocio post (which the Query Filter to show the child RFGs expects), so I have to fake it by setting the context to the negocio post which is the parent of the alojamiento post I'm viewing.

To do that I make an unassigned Views Content Template ("Template for View de RFG para chequear ahora") and insert the View into it.

That Content Template has no context itself until I give it one when I insert it into the shortcode module in the Elementor template for alojamiento posts.

This isn't easy because you are using Elementor and don't have the normal options available in the GUI that you would if you were using Toolset templates. I had to manually construct the shortcode to insert the Content Template and tell it that the source was the parent negocio post, i.e.

[wpv-post-body view_template="template-for-view-de-rfg-para-chequear-ahora" item="@negocio-alojamiento.parent"]

Then it worked on both the negocio page and the alojamiento page.

(Except I haven't mentioned the one change I needed to make, which was to modify the Query Filter of the View to set the parent based upon the current post in the loop instead of the page where the View is inserted, because of how we are inserting the View in a Content Template to change the context.)

#1071426

First, thanks.

Second, ... I wrote you from begin that it cannot working as it is in docs. Only issue was that I couldn't figured reason. This morning, I figured that t is because of Elementor, but I still didn't get to the conclusion of the right 'path'.

You did.

Last question related to ticket is:

As I have basically same issue (Elementor in the middle), but different nature:
> Display of the taxonomy of the another child of the same parent - and
> Display of the links (buttons) potentially several same level 'sister posts' (remember from other topic - How to display different locations or business types of same business?) - (BTW - this should be now easy as it is 101% same as from link tutorial from my last reply - and now you solved issue with Elementor in middle/end)

Should we open another ticket or keep on with this?

P.S. Wait for answer till tomorrow, as I hope so that I will now handle it and be able to close the ticket tonight.

#1072412

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I'll wait for another update from you...

#1072508
002.png
001.png

I'm done and 50/50 result.

A) Displaying links to same level of the child posts I created successfully and was simple.

B) Displaying taxonomies of another same level child post is sort of done. However, I obviously did it wrong, as display is vertical (image 001).

So, I did as follow

1) In Elementor is inserted

[wpv-post-body view_template="plantilla-para-siguenos" item="@negocio-alojamiento.parent"]

2) Above template have

[wpv-view name="post-view-de-siguenos"]

3) Post View de Siguenos run unformated Loop of

	<wpv-loop>
		[wpv-post-body view_template="plantilla-para-siguenos-redes-sociales"]
	</wpv-loop>

4) And template above have

<a href="[types field='enlace-de-red-social' raw='true'][/types]" target="_blank">[wpv-view name="taxonomy-single-view-de-siguenos"]</a>

P.S. At this point, everything is lined up well (see 002) if I useif I use

<a href="[types field='enlace-de-red-social' raw='true'][/types]" target="_blank">[wpv-post-taxonomy type="red-social" format="name" separator=""]</a>

5) Finally, Taxonomy single view run loop

	<wpv-loop>
		[types termmeta='iconos-red'][/types]
	</wpv-loop>

PLEASE< where I make mistake?

#1072574

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

This is the structure we are looking at, right?

            negocios
          /          \
         /            \
   alojamientos     sígue nosotros
                    (tax: redes sociales)
                    (termmeta: iconos red)

And on the alojamientos post you want to display the term fields iconos red associated with the parent negocio.

Well, you are navigating that tree correctly, and I think the vertical display is inevitable because you are using nested Views to get to the icons and each View includes its own wrapper div, which by default are block-level elements that always start a new line.

The next Views update, currently in testing, will let you output "raw" Views, which will actually enable you to display nested Views without the wrapper divs, so you should be able to get the to line up horizontally.

Or you can add some CSS to change the display type of these divs to inline-block so that they stay on the same line (you'll need to look at the page source to work out what CSS selector can best target those divs).