YTread Logo
YTread Logo

How to set up database relationships | JetEngine from A to Z course

Mar 29, 2024
Now, if there is one topic that strikes fear into many jet engine users, it is

relationships

, no, I am not talking about personal

relationships

, but

database

relationships, one to one, one to many, many to many, but they don't have to be scary at all and in this Introduction Video. I'll show you how to create your first relationship, how to add the data to your listings, and finally how to insert it into your templates now. This is an introductory guide if you want to see more examples of aircraft types. engine ratios, let me know in the comments section below and I'm sure I can work with croco block to create some more advanced guides for you, but before I get started let me quickly introduce myself.
how to set up database relationships jetengine from a to z course
My name is paul c from wp tets and me. I'm here working with croco block to bring you a series of tutorials on their popular dynamic tool plugins such as jet engine and jet smart filters. Now, if you're ready to start learning, let's jump on the computer and see what we were working on today. As always, let's start by taking a look at what we're actually going to create throughout this guide, so we go back to my test site that you've probably seen in the previous videos and if we scroll down, there's the list. of properties now any of the properties can be rented by a specific agent that agency or agent is dynamically linked through a relationship between the agent and the property now one agent could be an agent for multiple properties and that is what we are going to do Look today at how to create a one-to-many relationship, so let me show you what I'm talking about.
how to set up database relationships jetengine from a to z course

More Interesting Facts About,

how to set up database relationships jetengine from a to z course...

This is the first property. We click and open it. Take a look at the right side. We move down. We have an agency. contact and this is the agent that is letting this property so if we go back and take a look at a different property for example Edinburgh Heights we will open it and have a different agent there if we go back out and take a look at something like poolside luxury apartments hopefully we'll have a different agent again and there we go we have Williams properties so this is all set up through a one to many relationship so basically one agent can manage multiple properties and that's what we're going to work on, so let's take a look at how we create this relationship now to get started.
how to set up database relationships jetengine from a to z course
I already created a properties custom post type. I've done this in previous videos so you can see. This is what we are starting with. This is what we've used in several of these videos on how to deal with dynamic plugins for jet engines, etc., so what we're going to do is take a look at what's inside. you can see we've got the featured image, we've got a gallery associated with it, the address, the kind of things you'd expect to do as a typical custom post type, especially when you're working with listings, but what I want to do now is link this with the actual provider, the people who will be renting these properties, so how do we do it?
how to set up database relationships jetengine from a to z course
It's pretty simple, we need to create another custom post type which we will then link to. together using a relationship jumping back to the panel now we are ready to start setting things up so I already created my custom post type for my properties like I already said so the next thing we need to do is create one for our provider or agent do it, we're going to go back to jet engine and we're going to go back to post types, there's our properties, now we're going to add a new one and we're just going to call this agency.
You can click below to create the post types, like for us, we don't worry about the tags, we can leave them as is, but if you want to customize them, you can do the advanced settings which we'll go into here and What we're going to do is make sure that everything is set up the way we need to be able to set this up as hierarchical if we wanted to, but it's not necessary because we're going to keep this structure really simple. It's just going to be one level, and then we'll go in and say we want to add an additional field here and we want it to be the thumbnail so we can put the person's logo or photo, whatever. you wanted to do now once we've done that, the next thing we're going to do is just add a couple of metaphiles.
This example is going to be pretty simple, but the principle is more important than the details that we cover in this particular video, what we're going to do now is call this agent on the phone. I click below, come on, we leave all those other settings as they are, okay, we'll close it and add another one. meta field and we'll just call this agent email and click below and that's perfectly fine too so we'll leave them as they are okay so that's the basics we'll add our custom post type and then when Going back to our post types, now we have two, so if we look at them, we need to make sure that we understand one simple thing: the relationship between these two custom post types, so for example, an agent could have multiple properties and that's the way we're going to work, we're going to work with a one-to-many relationship, but you're not limited to that, you can do one-to-one, many-to-many or one-to-many, but the principles like I say once you understand how This works, it's much easier than it seems at first, so the custom post was created.
Now we need to create or define that relationship between the two. To do this we move on to the relationships option in the jet engine menu and inside we have a list of any or all of the post relationships we have created, click add new and from there we can now set up the basics we need to this particular relationship, so the first thing you want to do is create a name now, I would recommend that you create a name that immediately defines exactly what's going on, so we're just going to say agent to property relationship, that means when I look at my relationship list I can see exactly what relates to the following, we have the parent post type and the child post type.
This should be self explanatory. In this example, the parent would have child entities or child post types that would be the properties. To do that we change the main post type and from there we have all the options available and we will go down to agency, which is the custom post we just created. Next, the children of the agency will be the properties. so we'll choose properties from there, so those are the first three sections set up and hopefully that makes sense so far. Next, we have a type of relationship. If you don't understand how these relationships work, there is a link to the help documentation, but let me quickly tell you how it works one-to-one, meaning an agent can only connect to one property.
Next we have one to many so you have one agency or one agent could have multiple properties so the relationship will be one to many and finally you will have many to many which means multiple agents could be linked to multiple properties , so if you had one agency or you had properties managed by multiple agencies and you wanted to list all those multiple agencies, you set up a many-to-many system. The example we are going to do is have an agency with multiple properties, so it will be one to many, then it will have the parent. relationship now most of the time there will be nothing available to you within you, but from time to time you will see some options.
Let's leave them as they are for this example because I don't want to get too complex and too deep. Going deeper into the whole process, I want to give you an overview of the basics of how this works, then we have advanced settings and what all this really means is: do you want give the child and parent the ability to bond? the opposite, in other words, underneath a parent post type, so you could work with an agent, then you could link them within that custom post type to the different properties, and conversely, you could then edit or create a property and could bind it. down to the agent associated with it for this example, having the bidirectional option makes life a little bit easier because no matter which direction we're working in, we can create that relational link, with that said, now we've set everything up. we need above, we're going to click on add relationship and that will be a relationship created now before we move on to the next step, what we need to do now is just create a couple of agents so that we have something to work with within our relationship. so what we're going to do is go into the agency section and we're going to add new things.
Now I'll show you each of these. I just want to quickly show you how the relationship works in this context. and we also take a quick look at the relationship and how it works in the context of creating properties, but let me show you what we have to start with, so we'll just say we'll call it agent a and from there we'll just add some content, just some text For basic placeholder, we'll enter a phone number, so we'll just enter something that doesn't really matter what it is and an email address in the same way. Again, there we go, we're going to set up a featured image to have someone there that we can link this to so we have an image to work with and then this is where the relationship comes in because right now we've created an agent, we have properties linked, we have properties created, but there's no link, there's no relationship between the two, so what we need to do is start typing here, so we'll just say Edinburgh, as you can see, for example. there are edinburgh heights.
I'll click to add it, so now we've created an agent. We've also created that relationship between this particular agent, agent a, and this property in edinburgh heights, so once we publish that, we're going to create our first agent and I'm going to link that first, so I'm going to go through that quickly and add a few more in there , but before we do that, let me jump over to the properties and show you the same thing in reverse so this is linked to Edinburgh Heights, let's go to our properties and we'll just take a look at Edinburgh Heights inside, so there it is, we'll click to open it up and you can see if we scroll down, now there's our selected agency and you.
I can see that agent a is selected there, so it's very easy, whichever way you want to work, this will bind to the relevant data, so we'll go ahead now and set up a couple more agents and then we'll take a look. glance. In the next stage of working with this particular project, we now have three agencies all linked to the relevant properties, so the next thing to do now is create a way to generate the data for a particular agency and then place that in the template for our sole proprietorship template now to do that we need to create a new listing to do that we just come to jet engine and listings and from there we can create our new listing so let's select add new and we're.
Let's set the parameters now for this so that the list source is a custom post type, so the list source is post, but you can see we have other options available. The next step is from the post type where we want to extract the data from. So for this example, we want to go down and choose agency, then we'll give it a name, so we'll just call this agency property list, then we can choose what we want to use to create this list. We have the option to choose between Elementor and Gutenberg. If you're using gutenberg, we'll stick with Elementor for this example and click on create a list which will take us to Elementor and we can start setting things up.
So the first thing I want to do is make sure that we have the correct data entered, so we'll scroll down and go down to Settings and inside of there we have Got the list settings option, click to expand it and you can see why we set this when we create the list. The first two options are correct. The source of the listing is a publication and where we get that type of publication from is the agency I want. However, the width of the preview is set because it will be located in the right column, it is not very wide.
I want to set it so that when I create this listing it gives me a better chance of seeing what it will look like when I actually insert this into the design, so I'll set it somewhere around 350 pixels, it doesn't have to be perfect but close enough for us. will give a good starting point. You could then make the list clickable if you want and if you enable that you can choose where you want to create that link from, so in other words we can choose between the permalink and a bunch of other options. The permalink would basically take you to the listfrom the agent, but we're not going to worry about that, we want to keep this simple, but like I say, if you want to see a more complete tutorial on how to work with more advanced relationships, let me know in the comments section below and I can take a look at how to create something in the future covers more advanced relationships for now, let's keep this simple to get the concept stuck in your brains so you understand where we're going with all of this, okay, now that we've done that, the next thing we need to do is Start creating the different widgets and place all the different elements in our layout.
Let's go back to our widgets and start extracting all the data. Scroll down until you reach the option to list items. Now these all have to do with the jet engine and this is how we will use these different tools to make sure we have the best opportunity. to extract all the data and do all the things we need while we take the inside of the jet engine, so the first thing you do is enter the featured image of the agent we're dealing with, so we're going to dynamically drag and drop . image on our page and you can see that now the post thumbnail immediately appears in this example, that's perfectly fine, that's exactly what we want, so next we're going to set some alignment parameters there.
We want this to be a Linked Image, so again you can set this to link to a permalink so you can take a look at the agency or agent related in this particular section. We'll leave it as is, though the image size we're going to use. to set this to be something like medium for example so it looks good and obviously you can go back and edit this if you find that the images aren't high enough quality so the first thing to do is go back now and let's go a Let's go back to our widgets and this time we're going to bring in a dynamic field, we're going to drag and drop it there and you can see that this puts in what it thinks is the right thing, the title, in other words, the name of this. particular agent or agency and again, that's perfectly fine, we're going to work with that to speed things up, although let's just duplicate this and then under there now we can set whatever parameters we want, so this time we want to put some of the fields customs that we created, so we're going to get to the source and you can see right now it says post term user object, we're going to change that to metadata, now the metadata will allow you to easily reference any metafield that you want. that you have created as part of your custom post type or if you have just created custom meta fields as part of a normal post type, you can reference those that use the same technique, so we will choose metadata under the meta fields so that now we can choose. and choose which subject field we want to reference, click to expand and you'll see all the different meta fields that we've created in all of our different custom post types and custom meta fields etc., luckily they're all listed within you.
They're all also sorted basically by the custom banner that the data is pulled from so you can see under agency, we have the agency phone, the agency email, and the related properties, we'll just choose the agent phone and that will be gone. in the phone number, so now if you want to format this and put additional data in it, we can go down to the output enable custom field. What we can do is now we can put something before, so let's just put it. say y colon and a space so people know that's the phone number, but you can put pretty much anything inside you, including html.
Then we'll duplicate it another time and this time we'll do it. email, so again the metadata is perfectly fine this time, we're just going to change this now to the next agent email. Let's change this to email. One of the cool things that I like about this is that we can also filter the field output, so let's enable that and the callback may sound a little confusing, but what it really means is how you want to output this data, so we'll do click there and you can see we're going to say click. you can enable that, you can see that it now includes this and if we mouse over it, it will now become a link that we could immediately use as an email.
Obviously you could be a lot more creative with this, you can have this link through and you can have a contact form that includes the relevant email address and lots of really creative stuff, but that's more a case of dealing with creating custom listings and it's all about creating custom relationships, so let's keep this really very simple, okay, so let's go. To say we're happy with the way everything looks, all we're going to do now is hit publish once we've done that, that will create our list item, so now we're ready to move on to the next stage With our custom list created, we are ready to go ahead and put this data into our template to do that, we will go to the template section for Elementor and we will go down to our theme builder from our theme builder we will open. the property is edited individually with that with Elementor and then we are going to create that relationship and put the data in it now to do this I have already created a placeholder so if I scroll down you can see we have agency contact, so What we need to do is just do a listing search and that will open our listing grid, so let's drag and drop it into this section on the right side and you'll see that it now says: select a listing to display. we come to the left column, you can see that the listing is the first option of the general tab, let's click on that and we'll just choose what we want, which will be the agency property listing, click on that and that.
We'll just enter all the relevant data, so this will just show all of our agents. Let's set the column to be one and you'll see that we're using the template we just created, but pulling all the data in which is obviously not what we want in this example, we just want to show the one that's actually related to this property in particular, so how do we do it? We need to create a custom query. This is the point that probably causes the most confusion and frustration. for anyone who's not really sure how to work with creating these relationships and then generating that data, what we need to do is go to the post query section on the left side, we'll open it up now and we can configure the advanced settings. query parameters inside here, so we'll add our first element so we can then choose the type from there.
We have five different options currently, we will choose the post and author parameters because what we need What basically happens is that when you take a look at a property, you have a unique identifier for that particular property, so we will take that query that shows the information on the page and then we will link it through the relationship. to the agent that is actually associated with that property, so we can't just drop in a metafield or something, we need to create a shortcode that tells it exactly how to reference that data and what we want to do now, that sounds complicated but the The reality is that once you see how this little string of code is made up and you can copy and paste it and then just edit what you need, it's really not as complex as it may seem at first glance, so first of all we need the template initial for This little snippet now the link for this will be in the description below so check it out so I don't have to copy exactly what I'm writing right now so if we take a look at the knowledge base for this . particular function, you can look at this, paste the macros and there are two types of macros: there are related children and then there are related parents and then you have the slug post type.
This is where the confusion really tends to come in when let's say post type slug, do you think I'm copying this and placing it exactly as it's made? The reality is that no, you don't know. What you need is to know what the actual slugs are for your custom post types, specifically the ones within the relationship, so let me show you what I'm talking about, we go back to our custom post list, we have agency and properties, then there's the post type, we have agency and properties, so that's what we need to use. to actually tell this little shortcode where the data is within the relationship, in other words let's look at using this in context now because a property is a child of a parent, in other words the property is a child of the agent . which is the parent that we're going to need to take this second shortcode that's related to the parent and then we're going to say where we want to take it from, so we're going to copy that little piece of code and it looks like we're going to go back to element or we're going to delete that post inclusion by identifiers.
I'm going to leave her in there. Now you might think that's all you have to do and you can see that no data was found, that's because it's not. What we need to happen, we need to change the second half after the little pipe symbol that says post type slug to the slug of our custom property type. Just go back to the listing and you can see that there is our slugs and properties type post agency we will simply take the name of the main agency in this example agency, so we will select that copy and return to our template.
Then we'll just replace where it says post slug type making sure it's after the little pipe symbol and before the percentage symbol, we're going to paste it there, so now we say agency related parents; in other words, it will look up the related parents of the agency custom post type and you'll see that immediately now it gets the relevant data for this particular sample of data that we have on screen for the relevant agent and that's how we create that link so now you can set any other parameters if you want, so if you had multiple agents inside, you can I want to set additional parameters using a variety of different things like, for example, types and things like that, but now we've created that relationship between the property and also the agent associated with her.
Let's refresh this, take a look at our actual site. and see this in action, so let's go back to our sample page and if we scroll down, take a look at the first one, which is the way the industry, we'll click and open it and then you can see there's our option to contact the agency and you. I can see they are rentals in Windham, we come back from there and go to another one. Hopefully this time I'll get a different one and you can see that there we go to William's properties and if we scroll down to something like, for example, let's try Edinburgh Heights.
You can see that gives us an agent, so now we've created that relationship, we've built it into our templates, we've created custom listings, all that kind of cool stuff is set up for us now and hopefully what you have. What's seen is good, yes there is a bit of a learning curve to understanding these shortcodes and to be honest this is another one of those areas that I think really needs to be expanded considerably to get a solid solid understanding. I hope this video has given you at least your first steps in getting comfortable working with relationships and seeing how important these macros or shortcodes or whatever you want to call them are in the entire process of creating these relationships, but as I said earlier in this video, If you want to see more complete relationships covered in another dedicated tutorial, let me know in the comments section below and I'm sure the guys at Croco Block would be happy for me to create more content showing them how to do just that, so that It is the jet engine. relationships in a nutshell now, while this is a fairly simplistic example, the skills and techniques covered are much more important once you master the foundational skills, you can be much more creative now, as always, all applicable links for everything What we have covered is in the description below.
My name is Paul C and until next time, take care.

If you have any copyright issue, please Contact