OK, I figured out how to solve this a bit more elegantly. Add these codes to wp-content/themes/[theme-directory]/functions.php
add_filter('query_vars', 'metakey_queryvars' );
function metakey_queryvars( $qvars )
{
$qvars[] = 'not_meta_key';
return $qvars;
}
add_filter('posts_where', 'metakey_where' );
function metakey_where( $where )
{
global $wp_query;
global $wpdb;
if( isset( $wp_query->query_vars['not_meta_key'] )) {
$where .= $wpdb->prepare(" AND $wpdb->posts.ID NOT IN ( SELECT post_id FROM $wpdb->postmeta WHERE ($wpdb->postmeta.post_id = $wpdb->posts.ID) AND meta_key = %s) ", $wp_query->query_vars['not_meta_key']);
}
return $where;
}
What the above codes do is adding a custom parameter called ‘not_meta_key’. So now you can do this:
$myposts = get_posts('category=3¬_meta_key=feature-sidebar');
Sorry to hijack this thread, but I have a similar problem. So I’m wondering if anyone has a clean solution to this problem?