Title: Using conditionals with custom fields
Last modified: August 19, 2016

---

# Using conditionals with custom fields

 *  [Ryan](https://wordpress.org/support/users/daobydesign/)
 * (@daobydesign)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/using-conditionals-with-custom-fields/)
 * Hey folks, have a bit of an advanced WordPress question. What I’d like to do 
   is use a conditional to determine if a custom field has content (no problem),
   and then if it does, display the post, if it doesn’t, move on to the next post(
   also, not too much of a problem) – the catch: I only want to display a single
   post.
 * Anyone have any ideas how this might be done?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [nudnik](https://wordpress.org/support/users/nudnik/)
 * (@nudnik)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/using-conditionals-with-custom-fields/#post-696485)
 * Look at the code in the search-everything plugin. I think you’d need to write
   a custom SELECT query using whatever join it says for searching metadata, and
   check WHERE [certain custom field] != ”.
 * The dirtier (but easier way) would be to have a query that selects the maximum
   number of recent posts that might not have that custom field set (i.e. 10), then
   loop through them. When you find one with the custom field set, then display 
   that post and break out of the foreach.
 * The latter could very easily break, though, and puts an unnecessary load on the
   database.
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/using-conditionals-with-custom-fields/#post-696486)
 * Another search plugin option, though this one already works with custom fields:
 * [http://guff.szub.net/2006/04/21/search-custom-fields/](http://guff.szub.net/2006/04/21/search-custom-fields/)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Using conditionals with custom fields’ is closed to new replies.

## Tags

 * [conditionals](https://wordpress.org/support/topic-tag/conditionals/)
 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 3 participants
 * Last reply from: [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * Last activity: [18 years, 3 months ago](https://wordpress.org/support/topic/using-conditionals-with-custom-fields/#post-696486)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
