Skip Navigation

[Resolved] Creating a View that loops through a related CPT – List View, 3 fields

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

Problem: I would like to know how to recreate a design created in PODS, using Views.

Solution: It's best to get an understanding of how Views works, then read about how to insert custom fields using the Fields and Views button. Check out the documentation links below for more information.

Relevant Documentation:
https://toolset.com/documentation/user-guides/digging-into-view-outputs/
https://toolset.com/documentation/user-guides/view-layouts-101/
https://toolset.com/documentation/customizing-sites-using-php/functions/

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

This topic contains 16 replies, has 2 voices.

Last updated by laurieH 6 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#625936

Tell us what you are trying to do?
I am comparing Toolset with PODS in a Beaver Builder - Beaver Themer environment. I was able to build what I wanted with PODS and am trying to get the same result with Toolset. The section that I am having trouble with is the list of ingredients. I tried to do this by using the connections to the Toolset fields in Themer, but many times I could select the field using the connection tool, but the connection would not be populated. The Toolset Template connection DOES populate, but I haven't been successful. My goal is to create side-by-side examples of how to do the same thing in both environments. Previous reviewers have given up on Toolset and just continued with a PODS review which I think is unfortunate.

Is there any documentation that you are following?
I have been consuming all the documentation and videos I can find for both Toolset and PODS. Not following anything in particular.

This is how I listed ingredients in PODS

<div>
[pods]
    [if recipe_ingredient]
    <ul style="list-style-type:none">
        [each recipe_ingredient]
            <h5>
            <li><a ref="{@permalink}">{@quantity} {@unit} {@post_title}</a></li>
            </h5>
        [/each]
    </ul>
    [/if]
[/pods]
</div>

This is how I tried to do it in the Toolset Template for Recipes

<div>
[types]
    [if recipe_ingredient]
    <ul style="list-style-type:none">
        [each recipe_ingredient]
            <h5>
            <li><a ref="{@permalink}">{@quantity} {@unit} {@recipe-ingredient-name}</a></li>
            </h5>
        [/each]
    </ul>
    [/if]
[/types]
</div>

Is there a similar example that we can see?
hidden link (Created with PODS and Beaver Themer)

What is the link to your site?
hidden link

#625985

Hi, the second example you provided there looks like a hybrid of PODS data displayed in a Toolset Content Template. From your description, it sounds like you want to make a comparison between these two systems. If you want to explore a Toolset solution, then it probably makes sense to use Types and Views in the Toolset example instead of PODS. The "if" conditional, the "each" loop, and the values like "{@permalink}" are all specific to PODS, and should be replaced with their counterparts in Views and Types.

If I were trying to do a Toolset-only version, I would begin by creating a custom post type called "Recipe Ingredient", which is a child of "Recipe". Add custom fields for quantity, and unit. The title of the Recipe Ingredient post can be the ingredient name, or you can add another custom field to capture the ingredient name. This approach will allow you to create a View of child Recipe Ingredients and place it in the Recipe Content Template. The View of child Recipe Ingredients will include the quantity, unit, and ingredient name in the Loop Output.

#626011

Thanks for your response, Christian.

The Toolset and PODS examples are hosted in two separate environments, Staging 1 and 2 respectively, so they are completely separate. I was unaware that the PODS HTML example, outside of the fields referenced, was very specific to PODS. Thanks for the heads up!

In the Toolset example, I have a many-to-many relationship between recipes and ingredients. The items I am trying to loop through are in the intermediate CPT recipe-ingredients which has the fields quantity, unit, and recipe-ingredient-name. Can you point me to example HTML for Toolset that shows how to display multiple fields from a related entity, not just the key field? Or correct my HTML so that it will work with Toolset?

Thanks for your time,
Laurie

#626020

I recommend you check out this User Guide for an introduction to Views and Loops: https://toolset.com/documentation/user-guides/digging-into-view-outputs/
And this document that describes the different Loop layouts:
https://toolset.com/documentation/user-guides/view-layouts-101/
To create a list that loops over items, you'll need to generally understand these concepts. Most of this structural code can be created automatically for you using the Loop Wizard.

Then to display custom field values from each item in the list, you'll need to use Types shortcodes. You can insert these into the View using the Fields and Views button above the Loop Output editor. We have documentation about those shortcodes here: https://toolset.com/documentation/customizing-sites-using-php/functions/
Click the orange "More info" button in any field type to see actual shortcode examples.

#626031

Those links were very helpful, thank you!

#626041

I tried all different combinations of creating a view with a loop, with or without content template, and connected to Beaver Themer with no result. I've requested a Google Hangouts meeting so that someone can walk me through the correct process.

#626192

Okay let me know if there's anything you need from me.

#626689

I'm haven't had a response to my screen sharing request form. Can you check into that for me?

#626696

I'll check, but it often takes some time to get those scheduled. If you are able to share wp-admin login credentials with me, I can take a look at what you have set up so far and make recommendations. We may be able to knock it out before the video call can be scheduled. I will activate private reply fields here so you can share those details in confidence.

#626737

Hi, I'm seeing an error at the wp-admin URL you provided in the private reply fields. It appears that WP is unable to connect to the database. Can you check the settings in wp-config.php please?

#626740

Oops! Was cleaning up the database users 🙁 All fixed!

#626769

Okay the first thing I've noticed is that you have created a View of Recipes. However in the Loop Output Editor, you have included custom fields quantity, unit, and recipe ingredient name. Those fields are not part of Recipes, they are part of the Recipe Ingredients. So the View you have created should be a View of Recipe Ingredients, not Recipes.

Step 1: Change the View from a View of Recipes to a View of Recipe Ingredients in the Content Selection area of the View editor.

Step 2: Click the Screen Options tab in the top right corner of the View editor screen, and choose "Full Custom Display" so you can see all the editor panels.

Step 3: In Query Options, uncheck the box "Don't include current page in query result". This option can cause some unexpected problems, so it's best to uncheck it unless you have good reason to use it.

Step 4: In the Query Filter section, click the button "+ Add Filter" and add a Post Relationship filter.

Step 5: Configure the Post Relationship filter to show posts that are children of the page where the View is shown. We will show this View on a Recipe page. We only want to show Recipe Ingredients that are children of that Recipe page. This filter will accomplish that for us.

This should be enough to get you started. Let me know how it goes.

#626777

Thank you so much for the clear instructions 🙂

I'm stuck on step 4. I received an alert that before I can create a filter I need to create a parent-child relationship. When I go the relationship section the system is hanging and not displaying the relationship between recipes and ingredients. How can this be resolved?

#626781

I received an alert that before I can create a filter I need to create a parent-child relationship.
The alert seems to indicate that you did not set up a post relationship yet. That is required before you can create a post relationship filter. More information about setting up parent / child relationships between custom post types:
https://toolset.com/documentation/beyond-the-basics/post-relationship-concepts/implementing-one-to-many-relationships/#connect-post-types

#626783

The very first thing that I did was to set up a many-to-many relationship between Recipes and Ingredients, that created the intermediate CPT recipe-ingredients. I have been able to access it in the past, just not today. It appears that the relationship tab is hanging - displays an endless loading bar.