WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My apologies if this question has already been asked somewhere else, I searched but couldn't find anything. I am working on a tours website, there will be individual package pages that show some text, images and some other stuff.

On the right hand side of my single package pages I have a comparison table which is merely a custom WP_Query pulling out all packages from the database using the following code:

// Package fetching arguments
$pargs = array(
    "numberposts" => -1,
    "post_status" => "publish",
    "post_type" => "packages",

// Get out packages
$cpackages = new WP_Query($pargs);

I however would like the first item of this comparison table to be the current package the visitor is viewing. Say for example the user is viewing a package called "Tour A" on the right hand side I would like to pull out all packages but make sure that Tour A is at the beginning and highlighted then the other posts displayed.

I've looked into sticky posts, but they don't really apply to what I am wanting to do, because if someone is on Tour B, then it needs to be displayed first in the comparison table and then so on.

share|improve this question
up vote 1 down vote accepted

Loop over the $cpackages results twice, and rewind_posts() in between. first time only output when the id matches the current post id, then skip that id the second time through.

share|improve this answer
Nice solution brotato. Works perfectly! thank you. – Dwayne Charrington May 6 '11 at 0:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.