Using WP_Query to create custom queries

while reading my usual RSS feeds I stumbled upon this article on displaying your latest post.

It took me eye as I have been busy implementing similar things for my upcoming website, except I have been using WordPress’ WP_Query function to achieve the same results.

Basically WP_Query is used to create a seperate mini-loop outside of your main loop.  It has many advantages over using a custom SQL query like

  1. You don’t need to know proper SQL syntax
  2. It’s a core WordPress function, so if the database structure changes it will still work
  3. is more concise and uses less code
  4. highly customisable in that you can easy modify the post parameters (specify category, author, sort order, etc.)

The below is just a simple demo the grabs a link to the latest post.  It shows how easy WP_Query really is to use.


< ?php

$my_query = new WP_Query('showposts=1');
while ($my_query->have_posts()) : $my_query->the_post();
echo '<a href="' . get_permalink() . '">' . the_title('','',FALSE) . '</a>';
endwhile;

?>

(1 votes, average: 5 out of 5) Loading ... Loading ... Comment

Almost Transformers

Whitegoods in disguise


(2 votes, average: 5 out of 5) Loading ... Loading ... Comment

French Kangaroo


(1 votes, average: 5 out of 5) Loading ... Loading ... Comments

The Apocalypse has cometh

The internet has gone down, basically the same thing.


(Rate This Post) Loading ... Loading ... Comment

Costa Rican SWAT Team

Number one in the world.


(1 votes, average: 5 out of 5) Loading ... Loading ... Comment

A Flat Stomach Joke

A little boy walks into his parents’ room to see his mum on top of his dad bouncing up and down.
The mum sees her son and quickly dismounts, worried about what her son has seen.
She dresses quickly and goes to find him.

The son sees his mom and asks, ‘What were you and Dad doing?’
The mother replies, ‘Well, you know your dad has a big tummy and sometimes I have to get on top of it and help flatten it.’

‘Your wasting your time,’ said the boy.
‘Why is that?’ the mom asked puzzled.

‘Well when you go shopping the lady next door comes over and gets on her knees and blows it right back up.’


(1 votes, average: 5 out of 5) Loading ... Loading ... Comment

The Tiffany Bracelet Joke

Tiffany BraceletA lady walks into Tiffany’s. She browses around, spots a beautiful diamond bracelet and walks over to inspect it. As she bends over to look more closely she inadvertently breaks wind.

Very embarrassed, she looks around nervously to see if anyone has noticed her little accident and prays that a sales person doesn’t pop up right now.

As she turns around, her worst nightmare materialises in the form of

a salesman standing right behind her.

Cool as a cucumber and displaying complete professionalism,

the salesman greets the lady with, ‘Good day, Madam.

How may we help you today?’

Very uncomfortably, but hoping that the salesman

may just not have been there at the time of her little

‘accident’, she asks, ‘Sir, what is the price of this lovely bracelet?’

He answers, ‘Madam, if you farted just looking at it,

you’re going to shit yourself when I tell you the price.’


(Rate This Post) Loading ... Loading ... Comments

A Blonde Nurse Visits a Bank Joke

A very tired nurse walks into a bank, Totally exhausted after an 18-hour shift.
Preparing to write a check, She pulls a rectal thermometer out of her purse And tries to write with it.
When she realises her mistake, She looks at the flabbergasted teller, And without missing a beat, she says

“Well, that’s great….that’s just great….

Some asshole’s got my pen!”


(Rate This Post) Loading ... Loading ... Comments

Golf Club Sign

  1. Back straight, knees apart and feet a shoulder width apart
  2. Form a loose grip
  3. Keep your head down
  4. Avoid a quick back swing
  5. Stay out of the water
  6. Try not to hit anyone
  7. If you’re taking too long, let others go ahead of you
  8. Don’t stand directly in front of others
  9. Quiet please… While others are preparing
  10. Don’t take extra strokes

Well Done.

Now… Flush the urinal, go outside, and tee off.


(1 votes, average: 4 out of 5) Loading ... Loading ... Comments

Skinny Dipping Joke

An elderly man in Florida had owned a large farm for years.

He had a large pond in the back which he had fixed-up really nice; picnic tables, horseshoe courts and some orange trees.

The pond was ideal for swimming although he rarely did that any more.

One evening, as he hadn’t been to the pond for a while, he decided to go down and look it over.

He grabbed a five gallon bucket with which to bring back some fruit.

As he neared the pond he heard voices, people were shouting and laughing with glee. As he got closer he saw it was a bunch of young women skinny-dipping in his pond.

He made the women aware of his presence and they all went to the deep end.

One of the women shouted to him, “We’re not coming out until you leave!”

The old man frowned, “I didn’t come down here to watch you ladies swim naked or to make you get out of the pond naked.” Holding the bucket up he said, “I’m here to feed the alligator.”


(1 votes, average: 3 out of 5) Loading ... Loading ... Comments