 So, as you can see, using text on needs to speed up your size, and there's a lot of performance talks out there that are a lot of basic things like installing caching plugins, things you definitely shouldn't do, but dealing with clients a lot of the time in my job, I have to do a lot of code of view, and I have to do a lot of checks because if I don't do my job properly, then either the site gets hacked or it falls over after a hundred people visit, and these tend to be newspapers that have like thousands of people visiting every second or minute, and millions and millions of page views every week, I don't mind any year. So, I'm going to have to look at things, and there's a lot of things that they do, and it would work if you're on maybe five or ten people, but even then it doesn't work especially well. He wants a page that ideally loads in under half a second according to Google, which is easier than done, especially when you get to seven things. So, one of the main focuses I'm going to talk about today is taxonomy specifically, using them for purposes other than what people usually use them for. So, I'm going to cover actually creating them, because it's a lot easier than people think, especially if people aren't necessarily technically inclined. What's the difference between public and private taxonomies? A lot of people don't even know that private taxonomies are a thing, but I'm going to talk about that. Examples of how to make your sites faster, and one particular common example, that a lot of people build a certain way, but I'm going to show you a much faster way to do it, excluding things from your homepage. How to put things in like sliders and featured pages and sections in a very fast way, and checkboxes and flags and more general covering of the topic. So, first off, if you want to create taxonomy, you don't need to write the code yourself, go to this website, fill out the form, and it'll spit out the code at the end. I don't remember last time I typed in register underscore taxonomy, or register underscore custom post type, and then looked up from the codex, which options I wanted. I just went to this website, checked a few boxes, filled in a few text boxes, telling it what it was called, do you know what is it? Box, and then boxes, the claw, and that, and they figured out the right score, and then I popped the paste at the end. So, this is what their website looked like, and as you can see, they do a lot of regenerators as well, and always worth a look going around, things like if you write the plug-in header and we want to come into the top, and you don't remember what they're called, which I can never remember myself, it'll tell you all of those, and it'll let you just write into a box, and at the end, update code, as you can see, is the top of this large chunk of code, which I'm going to copy and paste into my functions, the HBO plug-in, and I don't need to worry about any of that, and so that's probably the easiest part of this, and it's probably something that a lot of people think is very complicated, but it's not really, you don't even need to understand that we just need to know how to copy and paste into a file. So, that's not out of the way. Public versus private. So, most people, when they deal with taxonomies, they tend to think of things like product categories, or brands, or manufacturers, or anything that they would organize that post-file, and private taxonomies do the same thing, but rather than having an archive page and a nice little menu on the side that you visiting my site would see, instead, it's a private taxonomy that I might use for internal purposes behind the scenes. So, this is more used for things like when you're on Bloopeter, and you pull out something from underneath the table, and I wish I had a cake right now, but it's useful for those kind of things, or for when there's something that you want to do that is quite heavy and complex, so you want to figure things out beforehand and move things behind the scenes, but they're not the kind of groups you want to share with a customer. So, these are the options that you would set, and these are flipped around. So, by default, taxonomies, when you register them in public, unless you say otherwise, and if you say false, it will set these three other values the other way around. So, if the public is set to false, then it won't show up on the front end, it won't show up in the admin area, and you'll have this taxonomy, but you won't necessarily even know it's there just looking at using to this. And WordPress Core itself uses these internally, for example, if you have ever done anything with nav menus, you probably think there's a custom post-type behind a single load of options, but actually, the menus themselves are custom taxonomy, and the individual items that you put in, like if I had a page in, it creates a custom post-type nav menu accent, and then it figures out which goes in which menu based on the terms. So, a lot of people are completely unaware of this, and it's completely hidden behind the user interface. So, again, publics have archives and templates, they show on the front end, and categories is a currency archetypal example. This is what everybody is used to, and private nav menu, that was the name I was looking for, is very useful, and again, these are hidden, and they can speed things up by being used behind the scenes, and they can also be used for other stuff. You can also have private taxonomies that do have user interface, but are not on the front end of the site for internal purposes. For example, let's say you have things on your site, and they need somebody to go and do them, so maybe tasks that we're going to do, and then in the admin area, you might have a private taxonomy called people, and then, or you might name it, who is this assigned to, and then tag people on individual posts, but no one outside of WP admin is ever going to see that, because it's a private taxonomy which has show you why to true and everything else set to false. So, that's a practical thing that you might have rather than something to speed things up. So, one thing that I generally recommend is adding a utility taxonomy, because sometimes you have things that would be helpful to know in advance for querying purposes, but you don't want to set a whole taxonomy up for them, because you know the only values in there are going to be yes and no, and that's not particularly useful. So, you might have a taxonomy that is general purpose, that you can add random markers to. So, if I'm sorting through a load of documents, I might have a load of stickers and stuff, and I might, you know, put a red dot on top of things that need adjusting, and then a blue dot on these that need to go off to this department, and at the end of the day, before they're all sorted, all the stickers are filled off anyway, but I might use it for those kind of things, or you might need to do markers. So, I'm going to register a utility taxonomy, I'm going to call it internal markers. I have set it to not be public, but I have set show UI in menu and rest to true. So, I can use the rest API of it, I can change it in the admin interface, and it will show up as a menu, but it will not show up on the front end. So, unless you have a login, no one will ever know this is even there. And that's all I need to do. And for the most part, you can have more than one of these taxonomies, and all you need to do is copy, paste, and change the word utility to something else, or change internal markers. And if you were on Frunzenberg for a short while, you might have seen me testing this as internal markers showed up in the sidebar. So, hiding post on the homepage, I'm going to use my utility taxonomy now to speed things up. But first, I'm going to go through the way that people usually do it, and how I might have done it in the past. So, this is the slower way, but it's the more path well trolling. So, a lot of people will create a whole new query which will be the main query modified, or they'll do it the better way where they filter. So, what we have here is a post meta value, and if the post meta value is one, then hide it from the front page. That's how most people do these things. So, here we are, we're modifying, if it's the main query in its home, then add a meta query where we're looking for hide from home page, and if it is not set to true, then show it on the front end. And this is a very expensive query. Expensive because it has not in, you always want to be querying for what you want. You never want to query for what you don't want because then the database has to sort of figure out. We have all of this stuff here, and we're going to have to go through each and every single one and pick out the ones that satisfy this, and then copy it all into a brand new table, and then we're going to run the query that Tom wants on this brand new table, and then we're going to erase this table because we're done with it and go back to the original one. That takes a lot of time, and then on top of that it's a meta query. You have post meta and you have taxonomy, and there's a reason we don't just store taxonomy and post meta, because it's slow. Post meta is very fast when you already know which post you want, and you just want to fetch this particular value. It's built for that. It's amazingly fast in that. In fact, it's so fast that when you do a query for let's say five posts, WordPress decides to go and fetch all the post meta for you in advance, because it's so fast. So if you do get post meta, you don't end up with a second query to the database because it just fetched them all in bulk. Whereas if you're trying to search on that table, you're trying to figure out, you don't know the post ID, but you do know the key and the value, and you're trying to figure out the reverse. It's just everything just grinds to a halt, and it's just like snails moving along. You don't want that, but it's very easy to implement, and it's kind of the thing that immediately comes to mind for most developers when they're doing this kind of thing. So this sort of thing is very common, and you'll end up them having a meta box in the back end where you've added a little checkbox or a custom field that you add, and you put the number one or the word true or yes in, and then you have an equivalent of this somewhere. So the fast way is to use the internal markers show on home page tag in there, and at this point now we have something we can query for, and we always want to be querying for what we want, it's not what we don't want. So rather than saying show me all the things that don't have this post meta, instead now we're asking for all of the things that do have this tab, which is orders of magnitude, sometimes thousands of times faster, both because we're using a taxonomy and because we're looking for what we want not what we don't want. So it also makes the query a lot quicker because it's now to write, because now it's just the one line, we just say utility, show on home page, and we're off to the races, rather than the meta query, which a lot of people find quite intimidating because they could go to the codex and figure out which values they want. Here it is, just a single line. A lot of people use tax queries sometimes, but even if you just, if you know the name of the taxonomy and the term you want, just step one is that the taxonomy is the key and the term is the value and that works just fine. And this does exactly the same thing as the previous query, so if we go back, we've just swapped this, the slow query that might cause havoc on our database, and I've seen queries like this bring down servers when they're on the heavy load, or not even heavy load, just a lot of people visiting to this, just a single line which is quite quick and it's kind of query you would expect to be quite common in WordPress. But we've got a problem, so if we go back here, I've just added a tag there and you might be thinking, well, I don't want to have to add that to every single post that I've got, that's a lot of work, what if an editor forgets, it's just, who can be asked with that and then nobody got time for it, so why not automate the whole process. So here I have, whenever I publish a post, I set the term on that post ID so that in the utility tax on me, I have show on home page, and now whenever I create a post, it will automatically add it. And if I ever wanted to remove it, then that post would no longer show on the home page because I'm going for what I want, not what I don't want, and if I remove that term, show on home page, then clearly I don't want it to show on the home page. So you can use a very similar process for galleries and featured areas, and it's kind of simple as well in terms of if I don't want this to show on the home page, I just click that little X there, rather than having to wrap around and on top of that, I kind of forgot to mention that I didn't build that user interface, it was just handed to me on a silver platter by WordPress. So I saved myself the time of having to build a meta box and implement a check box and make sure that it was working okay and then test it and then figure out with things like the whole selected, I didn't have to do any of that WordPress just handed me this. I can add other things in there just for my own personal users like maybe I really like this post and I want to do something like something in there as well, and I have absolutely nothing to do with how my website is built, or you know maybe it's going to in the future. Who knows, I have a lot of flexibility with this. So galleries and featured areas, you see for example, this is the Verge, they tend to have a big section at the top with like a nice little mosaic section with like their six top stories that they really want to push or in this case the single story that they really like and they want everybody to read. And you might also see things like on the Guardian where they have nice sections, where they have the sports bit and then a big line and then a box underneath with international news or here at the very top. They've picked Boris Johnson and Russia World Cup to be, you know, their number one story and then they you can see they've taken other posts and put them around but they've curated that. They've figured out what's important for them on that particular day and decided okay we're going to do that rather than just showing things chronologically. So there's some sort of level of importance in curating and showing to that. And again some people might use post-meta for that. But then you have the other problem that like for example here we have Google who's buying electric for $14 million and other sections in the tech-country website. And as you go down you see they have their chronological down here but they haven't picked up the top. So you might be thinking well okay I'm going to write a post-meta where it's like featured on homepage and I'm going to search for that and it'll be all great until the client comes around and says okay we have another section called acts which also means the same thing. So you go out of the second post-meta and then out of the third for gadgets and that and they're like well we want more than one and then suddenly you're ending up complimenting about 20 check boxes in this huge meta box which goes down and you're scrolling and scrolling and then they say they want this and that and you're just like and then you've got a query for them and the query is expensive because it's a post-meta query and it's so much to manage. Or even if it's just a simple thing like on the Apple website they have a few sections here but they had someone had to go through and pick these products and then pick the order and make sure that they go in the correct order and then they might have other sections maybe on the iTunes store where they have a selection of apps right at the top maybe the top 20 that they've picked for that day or the editor's choice who knows. So what I'm going to do is I'm going to register another utility tax on me and as you can see this is the same code as maybe several slides back but I've just changed utility in internal mark is to featured area and I've made no other changes but it's it's quite useful for the same reasons so I'm going to use this and the terms in this tax on me are going to be the featured areas. So I have a homepage featured area one for a slider and another example this is if you have a sliders tax on me you could have as many sliders as you want and you just add as many patterns as when you needed them and then just type post that way. So I have a top headline section and this is how I would do that and then when I'm in my back end area or I would just type top headlines in and then hey Presto they appear on the homepage in the top headline section and the query is a lot simpler than a lot of other examples and other than that it's just standard post loop at which point I can go to town on whatever slider or layout I want as a front end developer and at that point it's just you know business as usual but it's a much simpler query as well. So you also might notice that tax on me they have checkboxes versus tags so it might be that let's say I look at my top headlines section and it has subsections well that wouldn't necessarily work with that interface I showed you earlier with the little tags and cross buttons so this is where we can kind of then make use of categories versus tags in the hierarchical or non-hierarchical where you can have parents and child terms so it might be that instead I have a top level section and that is their headlines for that and that is some combination of the things that were flagged for the subcategories because I went through and I said okay I'm going to have a featured area and it's going to be the top headlines and then let's say for the morning and the afternoon I have top headlines for that and this top headlines is for the whole day I can do that by just putting things in the subcategories and then it shows up in the pair categories automatically or in this type featured areas so I can just set that by setting hierarchical to true or false and I can change this in the future or not it doesn't really make much difference once it's live so this is what that looks like using my first example of show on homepage and this is also useful if you have editors and they don't know what the areas are called if you want to use the left option it will just show them the list and if you want to use the right option it will auto-complete as they type I'm using Gutenberg as well for these examples but it works perfectly fine in the classic editor as well so as a recap I covered generating taxonomies so there's a website for that it's very handy you don't need to write a code it's just copy pasting and a few options there's a difference between public and private taxonomies a lot of people only use public and don't know about private taxonomies you can make sites faster by specifying what it is that you're looking for rather than what you don't want to look for and setting it as a tag it makes things like putting posts in a certain place or finding posts or removing things much easier especially if a hook that automatically sets a turn you can change it between categories and tags and that will give you some control over the user interface that you get and Anton know so I work at automatic and do a lot of code review per day I focus on performance and security and do a lot of community projects and I work at DAP we're hiring so have a talk to me later if you're interested and does anybody have any questions great, thank you great, thank you very much make one comment first which I kind of realized while I was sat down earlier I didn't want to edit my slides so this is all great when you have a brand new website and you're doing things but a lot of people already have websites that they're maintaining over the long term especially websites even just for my own website I might want to make that faster and I already have all this stuff stored in Postnetta for which how do I move all of this stuff over it's no good me telling you all this stuff if you already have 10,000 posts and then you do this and you're like oh well I didn't add this show on homepage term to the 10,000 posts earlier now I only have five posts in a different page there are two alternatives to that first just because you're storing it in Postnetta doesn't mean you need to move it to terms you can cock it so you can add all of this stuff and not use it and the premise that let's say in a month or two's time once you've got enough stuff to show on the homepage using that mechanism you can do that and that's good for things going forward you can also make it so that you have a WPCLI command which you run a single time which queries for all of the posts that have the Postmetta goes through maybe then goes through them and maybe batches of 50 or 100 and adds the term and then removes the Postmetta and then you just keep running it until it says there's nothing left and I know not everybody can do that on their website because they don't have the necessary access but in those situations a good way of doing that is to set it up locally pull all your data down do it on your own computer because you can do anything you want your own computer and put it back up so I could run a CLI command on my own website because it's a VPS and I have all that access but if I was dealing with a shared hosting website something that was maybe a pound a month of that and I just wanted it to run fast and I wasn't worried about traffic I just wanted everything to load in like half a second rather than 10 or 20 seconds I can download everything run it on this computer and then send it back up almost as if I was doing a migration only I'm migrating to myself so I don't need to change your route so that's another option I'm sure there's some other things you can do but I've not been told me that so questions quite literally read my mind because as I was sitting there I was thinking about something I've had in post-meta going how will I migrate it to you I don't know you've clearly just got some little link because you've just had my first question if you were doing something like that though so like you're mentioning and say running a custom CLI command would you have to would you have to configure that yourself like you could write your own function or something to actually write the migration where you query the post-meta and then insert it into your so you're still going to do that like work yourself obviously right yeah so there's no tools to migrate data that I don't think exists in the while already so you have some advantages in that these if you all went away and wrote a command to yourself they would all look about 95% similar it's basically you have a loop that goes around and off the query and inside the loop you're just like okay grab the post-meta set the term remove the post-meta next and those specifics of which post-meta that will depend on what you want to call your tags on me what you want to call the tags what you're using the tags for but it's the same kind of pattern the query itself you can probably just take straight from your front-end website because you've already written that query because you wanted to fetch those posts in the first place so if I go back and I have the original show on home page and I wanted to use that on my front-end but I needed to write CLI command well I've already written the command to fetch all the data up here and it's been running on my site for a while on all my existing data so I would take that query put it in my CLI command and then use that function there to set it so all of the building blocks are already there on the site because you built them when you built the site we're just adding a few extra bits and then there's this one throwaway command which you'll run once and then you're done with it you never need to touch it again I'm going to give it back to my questions page I think I'm throwing my questions down actually when you went back a few bits when you went to the because I was wondering how do you tell somebody you know you don't want it on you know you pre-filled in the show on home page tag which if you when you when somebody publishes you write I probably didn't want to do that so I was obviously thinking the more protective version you consciously added and so obviously you have last examples where you have check boxes about the way to do it so that makes it clear for the user interface point but at this point it's literally just a Chrome user interface on top of the data as long as the data's there you can quote on that's fine you could re-implement you could say I don't want to show that interface I want to build my own in a meta box which is what everybody's doing when they need to post meta in any way and you have that option that hasn't gone away it's just easier to use the stuff that core gives you but the other question related to that is because you have the underscores there you know that's a very technical look to can you use spaces and stuff to make it more user-friendly to that term in internal markets yeah you can do that for the purposes of just examples I just set the slogan the term name so exactly the same but you could go in and change under the settings because if I go back to I've set that to public to false but show you why it's true and one of those things it's not just going to show the little box in the sidebar it's also going to show it underneath like when you see the main categories and the main tags page on the post and you see them all listed you get the same interface unless you've turned it off but you can turn it back on to change things but you can go in and edit it and you can say okay well this is the slogan but I'm going to add a description and I'm going to add a title and you might want to add other things as well I don't know it's your website so you know however you want to use it but those are still options okay so from a client point of view because obviously you'd like to say it in a you know without it with the last logo or even it would look more professional you know to say it but okay that's good thank you so another option you could do is um so here I've got a term which says show on the homepage and then I have this hook which whenever you publish a post it adds show on homepage to all the posts and I could add another hook which says okay if show on homepage has been removed add don't show on homepage and I wouldn't want a query for those unless I wanted to show a list of the posts that you don't want to show because they might be like okay why isn't this post showing on the homepage did I remove that okay what's hidden from the homepage that would be the situation you want to do you never say show me your post that don't have this term you'd instead have either you look into as I said before you want to query for what you want so and sometimes for other reasons I can't think of right now with my mind this first plan you might want to have an A either or situation where you either have one term or the other term so that when you want this you query for this but when you don't want this you query for that and that's how you would go around that in those situations but as a rule of thumb if you ever have to write the words not in in a WEP query you'd be going down a very slippery path it's not going to end well I don't know but there are ways around it any other questions please so what kind of speed factor are we talking about in terms of let's say a few thousand posts or whatever so the problem with post meta query posts is that they are slow the way that they get slower is dependent A on the traffic and the server and B on the amount of posts you have so it's not a linear progression that if you double the number of posts it will get twice as slow instead it kind of go a bit like this because the work that the query has to do every time you query it gets exponentially larger so for example the taxonomy tables are built for finding things let's say I want all x with y anytime you have that kind of situation use the taxonomy so if I'm looking for a category it knows based on the tables where to look because it's been told in advance by core developers that their indexes we're going to be looking for these kinds of things but the post meta table doesn't have that so it has to build a new table every time if you have five posts it's slow but it's not amazingly slow because it's only five posts in the table but if I told you I'm going to copy all of your tables over and then do a calculation as I'm copying them and then copying them back and destroy it you're probably going to think that's quite a lot of work so when you see people implementing table upgrade processes they tend to be very cautious about speed whereas they realize it's happening behind the scenes with temporary tables whenever doing a post meta query so five posts it'll be a bit slow but it's not the end of the world not too much of an issue but a thousand posts it's got to go through and then it's got to do the same thing and it does the same thing if you're doing a not inquiry or if you're ordering randomly because it has to figure that out on the database and it's not very good at these things and the indexes aren't set up for that so generally avoid it whenever you can there are some situations where it's you kind of have to and that's why it's in there it's just unavoidable maybe because you're writing a CLI command and you know it's going to be expensive but it's only going to have one that's kind of why it's in there or for various other reasons that mind boggles but if you can't switch over to a tax only term but then usually it's a sign that there's a trade-off you're unaware of for example let's say you're on e-commerce website and people want to be able to fill by price let's say I only had a budget of 450 pounds and I want to buy a new computer from the moment of that so I'll go to let's say Amazon or e-buyer or in this case Tom's special PC purchasing company and okay I don't want to spend more than 450 so I don't want to be showing those products or want to filter them out so I might put between 200 because I don't want it to be an absolute terrible computer and 450 and then I realized this side's being really slow and like because behind the scenes it's going okay show me all the posts but they have to have a post meta with a number between this value and that value it has to do all the calculations whereas instead if I had at the beginning decided to set up a price tax on me and rather than putting each individual prices this is 2.99 this is 1.39 pounds or to 5 pence and instead said this is 1 to 5 pounds this is 5 to 10 this is 20 to 30 this is 30 to 50 50 to 100 and set them up in buckets and then put actual precise values in the post meta then that lets me query quickly and I have a little bit of a trade-off but I still have that position for when I need it I kind of rambled a little bit sorry so I'm presuming most of those custom field systems are probably using that aren't they yeah usually a lot of people find it quite easy especially with things like ACF it's very easy because it's by default and then once they because you know you're going through and you're saying okay this means that that that and that and the client will need this and this and this and they're all saved as meta by default and then it's usually after the fact that you've set that up you're going through the template to like okay I need to show all the things with X and all the things with Y and they're like oh well you don't realize that in pastual meta queries or you do and you realize the hard way and then you go oh yeah I've got 11 million post meta rows and you're not really pushed in the direction of tax on these items is that a conscious thing or because I'm very I was going to be the next question a lot of people aren't that aware of it or it hasn't been pushed in because if you hear about performance it's actually content performance or you know don't mind Bitcoin on every page or write content or you know don't do your thousand queries and have a hundred plugins so it is possible with ACF to use tax on these but tax teller too that's the same with a lot of frameworks that do these things so I've been told them at the time I think we've done a couple more minutes just because the next day you're not going to have to be in the quarter pass or we're okay does any more rush into time for another couple can I ask you about your query you had WP query where you did the feature of post one was that the full query because I just didn't recognize the syntax and this one is it missing something I just there's a reason you have to be patient I don't know what this is about okay so there's a few few changes here I like using just the letter Q but instead of writing the full or I use PHP 7 syntax okay okay so hence the square brackets a lot of the other options there basically pulling you from the default so I could I could speed this up a little bit further but that would be a talk about using the EP query so for example if I tell it that I'm not bothered about sticky posts it won't bother trying to figure that out if I tell it that I want posts that are published it won't try and figure out which posts are private and can I see them or not and show those it will just show me published posts which save some more if I set the author I want that saves a little bit of time as well or if I say oh what was the other one there's another one again the post type that helps as well so any kind of hints you can give to WP query about what you want even if it's set as a default usually it's best to give it error just to be sure and it saves a little bit of thinking time because you want to do as much of that kind of thinking on the PHP side and not have your database doing it because you've got a whole PHP process to that user doing that request but there's only one database server one process doing its work and you want it to do as little as possible so one of the things that I saw not long ago in the makeslack was someone who was trying to fetch stuff in the plugin repo and they were using the rest API and they wanted to be nice they wanted to be a friendly API user and only request what they needed and in theory that sounds nice because you know you're saving bandwidth but we have tons of bandwidth these days it's CPU and memory that's the problem so the difference between them fetching just the two or three fields they want and getting a standard response is with the standard response again I go and get fetched cake under here and say here you go I have I've been requested this a thousand times in the last 10 minutes I've prepared it in advance whereas the other one where they're like okay here you go oh but you don't want this icing and I'm going to take two of the candles off from here and you only want it on a small place here you go in the meantime I'll have a hundred other people are doing the same thing and I will my hands are full can you wait a little while I've got a queue so it's the same with the database you could fetch you know the entire post object or you could fetch a little bit but if you've got any kind of stuff like an object cache it's just easier to fetch the whole thing and then use something like WPList but to fetch what the PHP it's the same with stuff like random and I find that it's easier to pick a date and then pick the first post after that date more than telling it I want a random thing because it's much faster and you're doing it all the way to PHP better actually yeah and there's a lot of stuff you can do in this case by thinking a little bit in advance about how we're structuring our data because of how we want to use it we're saving ourselves a lot of time in the future so that decision about whether this post should be shown on the home page or not is happening when the editor clicks either A or B rather than every single time the home page is loaded and the MySQL server has to go away and figure all of this out and that's time that impacts our SEO and annoys the users and yeah anyway I'm going to leave it now I've got another question I think it was answered safe to say any other questions folks? speak now for 100 piece three, two, one done thank you give it up