Build Your Own Business Website header image

Community Library Website – Part 43, Simple Custom Query

Difficulty Level -

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 43rd in a series of live lessons on using WordPress and Thesis as a Content Management System (CMS). In this lesson we create the custom loop for our custom catalog page. We start by creating a simple custom query that we will progressively modify until it displays all posts from the last 60 days organized by custom taxonomy.

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 then we come to step 2 which is to actually create the custom loop. It looks like we’ve created a loop but actually, we haven’t. All we’ve done is we’ve looped through this data that we’ve captured. What we really want to do is we want to use that loop that goes out there and grabs our post.

And so, if we come back over to this and actually, what I really want to do is I want to change this from p to h3 and then I think I’m just going to string them all together. So if we put a concatenation operator there and another one and then delete these echoes… I can put that into one line. So now it’s h3 location h3 is what’s it’s going to be. That makes it a little simpler to read.

Now we’re going to add our loop and our loop is typically this statement here which I always just copy and paste and use verbatim. That is while have post… pardon me. First, we have to get our query in there and in this… our query starts off with this, my query = wp query. This creates a new instance of the wp query class. And then it says while my query has post, print out the post or do the stuff that’s below this.

Now we generally put an argument in here and so, the first thing that we’ll… the argument that we’re going to add is the post type, args equals… we’re going to say array because it’s going to become an array eventually. But for the moment, it’s going to be post type and then its location. No, pardon me. That’s catalog_items. So that’s our post type.

And so, if we hadn’t put that in tehrea and we’d have left this just as it is, what it would’ve done is it would’ve gone to a regular post. So we need to take it out of the context to regular post and so we add this argument, catalog_items to it. And now, it’s going to use a regular old loop with these catalog items and then we need to add an and while statement. And while… so that it knows to quit and… args equals array. Oh, I forgot my semi-colon. And then what we’ll do is we’ll just show Thesis teasers. So Thesis teaser… is it Thesis teasers or Thesis teaser? I don’t… I think it’s Thesis teasers. No it’s not. It’s Thesis teaser.

Okay so now what it’s going to do is it’s going to print out a Thesis teaser for each of the posts that meet this argument which, in this case is the post type being catalog_items and it’s going to do that for every instance of the location name. So we’ll save this and we will upload it and then we’ll come over to the site and take a look at it. And it didn’t work because Thesis teaser wants some parameters that I failed to give it. I forgot about that.

At the very least… well, we’re just going to take all 3 of those. Thesis teaser wants something specified about these 3 things: classes, post count, and right or left. So we’re going to save that, upload it and refresh it. Well, maybe that wasn’t the problem.

Okay wp query, args = array my query = wp query… post id… okay. Well, let’s go ahead and add the taxonomy here to this query and see if that… oh, maybe I misspelled this, catalog_items. Let’s see, someplace up here I have that again. Catalog_items, okay that’s right. Post type is catalog_items. I might just have done something funny there.

Okay post type = catalog_items. Post type… let’s just make sure that that’s the right…. yeah. That’s fine. Args = array my query = new wp query args while it has that location name… so it’s going through that process. Let’s just try this one more time. Maybe I failed to save that when I uploaded it.

Yeah, that must have been it.

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