[wp-hackers] Sorting Posts By Custom Meta Value

Gwkg Archive gwkgarchive at gmail.com
Thu Jul 23 21:05:46 UTC 2009

Ok I'm doing pretty good digging through the Wordpress Code and adding some
functionality to a theme.  Heres what I did so far

1. Made one of my categories a Directory with its own template

2. Added a drop-down box for posts in the Admin that lets the admin set a
meta_key verification_level with a value of 0, 1, 2 or 3

I want to sort on that value and I'm having a hard time figuring it out.

A couple things <em>almost</em> worked like adding a post_join filter

" JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id";

but that was returning duplicated posts

The closest (and easiest) mod was adding this line in category-9.php

$posts = query_posts(
"meta_key=verification_value&orderby=meta_value&order=desc" );

but the problem is a lot of posts don't have the verification_value set and
aren't being shown from that

What's the best way to grab the posts without a value set in that meta_key
and add them to the end of the post array without actually setting that
value in the database?

More information about the wp-hackers mailing list