Title: Problems with Querying Custom Fields
Last modified: August 19, 2016

---

# Problems with Querying Custom Fields

 *  [slaterino](https://wordpress.org/support/users/slaterino/)
 * (@slaterino)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/problems-with-querying-custom-fields/)
 * Hi,
    I am currently running a query using data from some custom fields. The query
   looks like this:
 * `query_posts('meta_key=event%20name&orderby=meta_value&meta_key=start%20date&
   meta_compare=>=&meta_value='.date('Y/m/d', current_time('timestamp')).'&posts_per_page
   =-1&order=ASC&cat=1');`
 * I’m using to create an events style page. The only problem is that I have some
   events which last for a number of week. On these events I have custom fields 
   for both ‘start date’ and ‘end date’. Events that last for one day just have ‘
   start date.’
 * What’s happening at the moment is that once the ‘start date’ passes for any event
   it is disappearing from the page. This isn’t too great when the event may still
   be happening for another three weeks. Basically what I want is a query that brings
   all posts unless their ‘end date’ has passed (and if they don’t have an ‘end 
   date’ it would be after their ‘start date’ has passed) but that also orders entries
   by ‘start date’ and not ‘end date.’
 * Is this possible?

Viewing 1 replies (of 1 total)

 *  [transom](https://wordpress.org/support/users/transom/)
 * (@transom)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/problems-with-querying-custom-fields/#post-2031737)
 * Since you don’t have end dates for some events, there really isn’t a way to do
   this query. If there was an end date, you could query for only end dates in the
   future.

Viewing 1 replies (of 1 total)

The topic ‘Problems with Querying Custom Fields’ is closed to new replies.

## Tags

 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [transom](https://wordpress.org/support/users/transom/)
 * Last activity: [15 years, 1 month ago](https://wordpress.org/support/topic/problems-with-querying-custom-fields/#post-2031737)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
