Build Your Own Business Website header image

Community Library Website – Part 44, Custom Taxonomy Query

Whoops, you've found some premium content!

Watch the opening clip of this video to preview it,
the full video is available to paid members.

This is the 44th in a series of live lessons on using WordPress and Thesis as a Content Management System (CMS). In this lesson we modify the custom loop for our custom catalog page. This custom loop will display recent posts organized by custom taxonomy. We use the new tax_query parameter to limit the display of posts to a single taxonomy term. This video gives an extended discussion of the new WordPress tax_query parameter.

Community Library Website – Case Study Part 1 – Site Organization
Community Library Website – Case Study Part 2 – Create Custom Post Types
Community Library Website – Case Study Part 3 – Custom Post Type Configuration
Community Library Website – Case Study Part 4 – Custom Taxonomy Decisions – Theory
Community Library Website – Case Study Part 5 – Custom Taxonomy Decisions – Practical Application
Community Library Website – Case Study Part 6 – Incorporating Existing Data Into the Project
Community Library Website – Case Study Part 7 – Creating Hierarchical Custom Taxonomies
Community Library Website – Case Study Part 8 – Creating Non-Hierarchical Custom Taxonomies
Community Library Website – Case Study Part 9 – Creating Custom Post Meta
Community Library Website Case Study – Part 10a – Restore the Database Using BackupBuddy
Community Library Website Case Study- Part 10 – Creating Custom Post Meta – Continued
Community Library Website – Part 11 – Importing Existing Data to the Website
Community Library Website – Part 12 – Prepare Existing Data for import by the CSV Importer plugin
Community Library Website – Part 13 – Import Existing Data Using the CSV Importer Plugin
Community Library Website – Case Study Part 14 – Date in Permalink Configuration
Community Library Website – Part 15 – Importing Images
Community Library Website – Part 16b – Final Data Import
Community Library Website – Part 17 – Add Thesis Post Meta to Custom Post Type
Community Library Website – Part 18 – Add WordPress 3.0 Menus
Community Library Website – Part 19 – Add Post Meta and Taxonomy Information to the Post Display
Community Library – Part 20 – Add topics and audience to book display
Community Library – Part 21 – Display the Rest of the Post Meta in the Post
Community Library Website – Part 22, Create the Permalink Structure
Community Library – Part 23 – Remove Custom Post Meta from Post Display
Community Library Website – Part 24, Add Taxonomy and Post Meta Data to the Teaser
Community Library Website – Part 25, Add Taxonomy Data to the Teaser
Community Library Website – Part 26, Adjust the Teaser Styling Using Design Options
Community Library Website – Part 27, Styling the Teaser Using CSS
Community Library Website – Part 28 – Fine Tune the Teaser Display
Community Library Website – Part 29, Designing a Custom Catalog Page
Community Library Website – Part 30, Using a Query String in a URL
Community Library Website – Part 31, Adding Custom WordPress Menus
Community Library Website – Part 32, Add Custom Menus to the Catalog Page
Community Library Website – Part 33, Add Another Custom Menu to the Catalog Page
Community Library Website – Part 34, Troubleshooting Custom Menus
Community Library Website – Part 35, Add Styling to WordPress Menus
Community Library Website – Part 36, Add HTML Markup to WordPress Menus
Community Library Website – Part 37, Add WordPress Menus to Archive Pages
Community Library Website – Part 38, Add and Style a List of Tags
Community Library Website – Part 39, Add a Search Box to the Sidebar
Community Library Website – Part 40, Add Links to the Sidebar
Community Library Website – Part 41, Add Taxonomy Drill Down Browsing
Community Library Website – Part 42, Custom Loop to Display Custom Post Types
Community Library Website – Part 43, Simple Custom Query
Community Library Website – Part 44, Custom Taxonomy Query
Community Library Website – Part 45, Add Thesis HTML Structure to Teasers
Community Library Website – Part 46, Display Posts from the Last 60 Days
Community Library Website – Part 47, Custom Loop If Have Posts
Community Library Case Study – Part 48, Increase the Number of Posts that Display on the Custom Catalog
Community Library Website – Part 49 – Naming Conflicts in Custom Taxonomies
Community Library Website – Part 50 – Find and Replace Semi-colons in the Database
Community Library Website – Part 51 – Modify Taxonomy Names Directly in the Database
Community Library Website – Part 52 – Sort Posts by Meta Value
Community Library Website – Part 53 – Show the Term Label Only when a Term Exists
Community Library Website – Part 54 – Sort Archive Posts by Meta Value
Community Library Website – Part 55 – Add Sort Order to Custom Taxonomy

Video Transcript

Okay so now what we have is we have a bunch of teasers. And if you’re paying attention as I scroll through here, you see… Madame Blueberry’s being repeated and it’s being repeated again. And the reason for that is that we discriminated about which post is supposed to show except that we said we want to show catalog items. And so what it’s done is every time… for each of the location names, it showed catalog items and it showed essentially, the 1st 10 catalog items over and over and over again which doesn’t do any good, right? That’s not what we want to accomplish and so, this is where we have to add to our array. Because now what we have to do is we have to add the new taxonomy query. Now this taxonomy query is something that has been added to 3.1 and what it does… WordPress 3.1 and what it does is it allows us to string a group of taxonomies together in a query. So theoretically, we could say, “Show me all of the books under fiction that have been… that are in a specific location, that are for children, that have a cal number of such and such.” And the taxonomy query allows us to string those various taxonomy parameters together into a single query. And before 3.1, that was impossible.

Well so what that means then though is that a taxonomy query is not just a name value pair. It’s actually an array of arrays. So it’s a… and each taxonomy that’s in the query is one of these arrays. Now in that regard, we… well, let’s just go ahead and get started with that.

So we’ve got our args equals array, now we’re going to add another argument to that which is tax_query and then again, array and we’ll drop down again. And that’s our first array, here’s our 2nd array and our 2nd array is for the one taxonomy we want to use and so that’s the first field is the name of the taxonomy. Taxonomy…I’m messing that up…taxonomy and its location…so that’s a taxonomy we want to query. The 2nd thing we want to do is we want to pull out that… the name of the taxonomy as the thing we care about so we are going to pick the field and that is the field name in this case and that field name is going to be the slug, that’s what we want to look for. So we’re going to look at the slug and then in the slug… it’s not a semi-colon, that’s a comma. And in the field name slug, in the taxonomy name location, we want to find the term of this location name that we got right up here, location name there. So we’re going to copy that variable, put it here and call it good.

So what’s happening now is inside of the post type catalog items with the taxonomy of location who has… whose slug has the location name, show all those posts. That’s what’s going on here.

Now someone has joined us here and don’t worry about the conversation. I mean, this is a very advanced conversation we’re having right now. When I get around to indexing this, this is going to be indexed not as an intermediate tutorial. This is going to be an advanced tutorial because this is advanced programming that we’re doing here in respect to WordPress but…so there’s a lot to learn before you get to this point. And having said that, next month, we are going to start having a 3rd session and in that session, we’re only going to take beginner questions so that we don’t scare off beginners with you know, these very technical conversation which are also useful to members but can rather be intimidating if you just log in and start.

And yes, this will… if you look at the Live Answer… Jared, if you look at the Live Answers section of the site, you will see that we post videos of every question and answer that happens in these Live Answers. So on Monday of next week, you’ll see this… video of this for example.

Okay anyway, back to this, we’ve got our arguments, the post type and we’ve done our taxonomy query. And this is a very simple taxonomy query so it seems like there’s a lot of stuff you have to do in order… essentially for you to say, “Get me in taxonomy location, this location name.” But it’s got a lot of stuff in it because it can be so much more powerful than it used to be able to be.

Okay anyway, we leave our query alone and if we save this and if we upload it and then if we refresh it… okay so now, we have audiobooks and we’ve got these audiobooks. Well actually, it looks like… yeah, we’ve got these audiobooks and then at some point, we got past the audiobook right here and unfortunately, because of the styling, what’s happened is the name of the next line, Bible and Reference has jumped up there which of course, is not exactly what we want it to do. But nevertheless, now, we don’t have that repetition because now, it is actually just taking those catalog items that are in those specific locations rather than what it did before which was display the first 10 catalog items every time.

0 Comments… add one

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
THIS IS A LIMITED TIME OFFER!
Subscription Options
0 comments… add one

Leave a Comment