Saltar navegación

[Resuelto] Nested views of related posts

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem: Nested Views of related posts don't always seem to be displaying the correct results sorted in the correct order.

Solution: It's not possible to order a View of post type A by a custom field in post type B, even if post types A and B are in a post relationship. Also you must check the post relationship filter context. In this case, one View's parent loop was the intermediary post type, meaning there could only be one related post from post type A and one related post from post type B.

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

This support ticket is created hace 6 años, 3 meses. 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Este tema contiene 11 respuestas, tiene 2 mensajes.

Última actualización por leeR-6 hace 6 años, 2 meses.

Asistido por: Christian Cox.

Autor
Mensajes
#1133728

Based on your example at:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/

I am trying nest a view in a view, so that I can display a list of albums and songs:

Album 1
Song 1
Song 2
etc.

Album 2
Song 1
Song 2
etc.

Is that possible? If so, can tell me how?

I think this is another support ticket that may be asking the same thing.
https://toolset.com/errata/nested-views-and-ajax-pagination/

#1133734

Sure, you can create the list of albums and songs like you described by nesting one View inside another. Here's how to do it:
- I assume you already have the Albums and Songs post types set up, and you have created some Album posts and some Song posts. If not, go ahead and do that.
- I assume you have already created a Post Relationship between Albums and Songs. If not, go to Toolset > Relationships and create the Post Relationship between Albums and Songs. If you are not familiar with this process, read more about Post Relationships here: https://toolset.com/documentation/post-relationships/how-to-set-up-post-relationships-using-toolset/
- I assume you have already linked some Albums and some Songs using that post relationship. If not, go ahead and link some Songs with some Albums so you have some testing content to work with.
- Create a View of Albums. Use the Loop Wizard to create an unordered list display. Add the post title shortcode in the loop so you can see the name of each Album.
- Place the View of Albums on a custom Page somewhere. You can use the Fields and Views button to insert a View in the Page content.
- Visit the Page on the front-end of the site. You should see your list of Albums.
- Now create a View of Songs. If you cannot see the Query Filter section, scroll up to the top of the View editor screen and open the Screen Options tab. You can activate the Query Filter panel here. Now add a Post Relationship Query Filter and select the relationship you created. Configure the Query Filter to find posts related to the current post in the loop, because this View will be placed inside the loop of your View of Albums.
- Use the Loop Wizard to create an unordered list in the View of Songs. Add the post title shortcode in the loop so you can see the name of each Song.
- Edit your View of Albums. Place your cursor after the post title shortcode and use the Fields and Views button to insert your View of Songs.

That's it. Let me know if you get stuck and I can help out.

#1133761

Hey Christian,

Thank you very much. I understand everything you said until the last line.

" Edit your View of Albums. Place your cursor after the post title shortcode and use the Fields and Views button to insert your View of Songs."

I don't know where to place my cursor. Is the "post title shortcode" in the loop editor?

Instead of albums, I have restaurants. Instead of songs, I have restaurant categories. Instead of tracks, I have order number.

This is a list of restaurants related to American.

enlace oculto

This is a restaurant page showing which categories it is related to.

enlace oculto

This is the the code in my Loop Editor for the View of American Restaurants. Do I place my cursor in here?

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop wrap="3" pad="true">
[wpv-item index=1]
<div class=" ">
<div class="col-sm-4">[wpv-post-body view_template="Loop item in List of American Restaurants"]</div>
[wpv-item index=other]
<div class="col-sm-4">[wpv-post-body view_template="Loop item in List of American Restaurants"]</div>
[wpv-item index=3]
<div class="col-sm-4">[wpv-post-body view_template="Loop item in List of American Restaurants"]</div>
</div>
[wpv-item index=pad]
<div class="col-sm-4"></div>
[wpv-item index=pad-last]
<div class="col-sm-4"></div>
</div>
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

#1134319

I don't know where to place my cursor. Is the "post title shortcode" in the loop editor?
Yes in the example I provided it's in the Loop editor, but in your example I can see that you have created a multi-column format with a Content Template in the Loop. So you can place your cursor in the Content Template to insert the nested View, or you can place your cursor directly in the Loop editor to insert the nested View somewhere else in the markup structure. If you choose to insert the View directly in the Loop editor, you will have to repeat the View shortcode in each wpv-item block, just like the Content Template shortcode is repeated in each wpv-item block, to create the proper loop markup.

#1134392

Christian,

Thanks for your patience. I am getting close!

This is a list of restaurants related to Seafood. As you can see, some restaurants are related to multiple categories.

enlace oculto

The problem is that the list of restaurants are ordered by Post Title - Ascending.

The main reason I used a Relationship instead of a Taxonomy, is that I want to order restaurants based on the Intermediate Post Type field "List Order" for each category. In a list of Seafood Restaurants, Hearsay on the Strand should be last. In a list of American Restaurants, it should be first.

When I do that, the list of restaurants is ordered based on the "List Order" field.

enlace oculto

Which is great, but the only category listed is "Seafood". I no longer see the other categories.

The only thing different in these two examples, is what I checked in the "Content Selection" box - "Member" vs. "Members in Member Categories Intermediary Post":

enlace oculto

enlace oculto

Any suggestions?

Thanks
Lee

#1134416

It's not possible to order a View of one post type by a custom field applied to a different post type - even if those post types are related in a post relationship. Is that what you're trying to accomplish here? I'm a bit confused by the use of Categories as Post Types...so maybe I'm misunderstanding. I will activate private reply fields here so you can share login credentials. It will be helpful for me to see how you have things configured.

#1134477

Okay look at this View:
enlace oculto
The content selection for this View is Member Category, with a post relationship filter, in any relationship, related to the current post in the loop.

Now look at these two other Views, where you have nested View 12865:
enlace oculto
enlace oculto
The content selection for these Views is different. 12893 is Members, but 12898 is the intermediary post type. In other words, the current post in the loop is different in 12893 and 12898.

When you nest 12865 inside View 12898, the query filter is looking for Member Categories related to the current intermediary post. There can only be one, because an intemediary post can only be related to one Member Category. When you nest 12865 inside 12893, the query filter is looking for Member Categories related to one Member. You can have multiple results, because multiple Member Categories can be related to the same Member.

So I don't think you can use the same nested View 12865 in both places. You should create a different nested View to nest inside View 12898, where you can apply different filter criteria. You will probably have to use a shortcode attribute to pass the Member ID from the parent View as an argument into the nested View's query filter. Then the nested View's query filter can look for Member Categories related to that Member. More information about passing arguments to Views:
https://toolset.com/documentation/user-guides/passing-arguments-to-views

#1135034

OK, wow. That's gonna take some time to process.

If I get stuck, do you contract your services? I don't see you in the list of contractors.

Thanks
Lee

#1135680

Our supporters are contractually prohibited from taking freelance work but I'm here in the forums if you get stuck.

#1136190

This is a kind of a new subject...

If I have a taxonomy called Restaurant Categories:
- Asian
- Italian
- Indian
- Mexican
- Seafood

And, Joe's Restaurant serves both Italian and Seafood, I would check both of those categories when editing the Joe's Restaurant Page.

How would I then display on the front end which categories Joe's Restaurant is associated with? Something like:

Joe's Restaurant
123 Elm Street
Joe's has really good shrimp pizza.
Categories:
- Italian
- Seafood

I can't find any documentation on displaying the taxonomies associated with a post. Is that possible?

Los hilos nuevos creados por Christian Cox y vinculados a este se encuentran a continuación:

https://toolset.com/es/forums/topic/display-taxonomy-terms-associated-with-the-current-post/

#1136264

We can address that in a separate ticket since it's a different topic. I have created that ticket automatically.

#1138192

My issue is resolved now. Thank you!