Build Your Own Business Website header image

Community Library Website Case Study – Part 43, Simple Custom Query

Difficulty Level -

Filed Under Topics - ,

Listed Under Lesson Subjects -

Applies to - ,

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.

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!
Subscription Options
0 comments… add one

Leave a Comment