Title: query_posts if meta_value != &#8221;
Last modified: August 19, 2016

---

# query_posts if meta_value != ”

 *  Resolved [Tom Von Lahndorff](https://wordpress.org/support/users/tomvon/)
 * (@tomvon)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/query_posts-if-meta_value/)
 * I’m trying to get all posts that have the meta_key ‘imgs’ AND have a meta_value
   for ‘imgs’ that is not nothing. I’ve tried meta_value = (with nothing following
   it as seen below), meta_value=False, meta_value=false, meta_value=empty and meta_value
   =0. Nothing works. I keep getting back posts that have a blank value for the 
   custom field: ‘imgs’. Thanks in advance!
 * `<?php query_posts('&meta_key=imgs&meta_compare=!=&meta_value=&orderby=rand&showposts
   =10'); if (have_posts()) : while (have_posts()) : the_post(); ?>`

Viewing 1 replies (of 1 total)

 *  Thread Starter [Tom Von Lahndorff](https://wordpress.org/support/users/tomvon/)
 * (@tomvon)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/query_posts-if-meta_value/#post-1454012)
 * Ha! I just figured it out. My fields were not blank but contained a single space
   for fields that were blank. Seem the code I used was right I just had to change
   it to:
 * `<?php query_posts('&meta_key=imgs&meta_compare=!=&meta_value= &orderby=rand&
   showposts=10'); if (have_posts()) : while (have_posts()) : the_post(); ?>`
 * for it to work. Hooray!

Viewing 1 replies (of 1 total)

The topic ‘query_posts if meta_value != ”’ is closed to new replies.

## Tags

 * [Blank](https://wordpress.org/support/topic-tag/blank/)
 * [boolean](https://wordpress.org/support/topic-tag/boolean/)
 * [empty](https://wordpress.org/support/topic-tag/empty/)
 * [meta_key](https://wordpress.org/support/topic-tag/meta_key/)
 * [meta_value)](https://wordpress.org/support/topic-tag/meta_value/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * 1 reply
 * 1 participant
 * Last reply from: [Tom Von Lahndorff](https://wordpress.org/support/users/tomvon/)
 * Last activity: [16 years, 1 month ago](https://wordpress.org/support/topic/query_posts-if-meta_value/#post-1454012)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
