Title: Custom Post Query/Filter Loop
Last modified: August 19, 2016

---

# Custom Post Query/Filter Loop

 *  [Chris Mason](https://wordpress.org/support/users/beardied/)
 * (@beardied)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/custom-post-queryfilter-loop/)
 * Hi, having some problems.
 * I have 4 custom post types each containing approx 8 meta fields. In each custom
   post type there is a field that contains a date as dd/mm/yyyy.
 * What i am trying to do is remove posts that contain a meta date field with a 
   date past todays date.
 * I really am lost any help would be appreciated.
 * My custom post types are ‘ukhol’, ‘holabroad’, ‘specevent’ & ‘daybreak’
    My date
   meta fields are ‘ukhol_ddate_meta’, ‘holabroad_ddate_meta’, ‘specevent_ddate_meta’&‘
   daybreak_ddate_meta’ The relevenat fields match the relevant post types (‘ukhol_ddate_meta’
   is in custom post type ‘ukhol’)
 * I have tried so many different ways that i have started working backwards!

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

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/custom-post-queryfilter-loop/#post-1820268)
 * First, it is very difficult to compare dates unless they are in the format yyyy-
   mm-dd.
 * Did you want SQL code to remove the posts so you could use phpMyAdmin or a similar
   tool? Or, do you want to not retrieve those dates in a query, but retrieve others(
   I think this is what you mean)? That is, only retrieve posts where those dates
   are in the future.
 * And, by ‘past todays date’ do you mean the date is earlier than today?
 *  Thread Starter [Chris Mason](https://wordpress.org/support/users/beardied/)
 * (@beardied)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/custom-post-queryfilter-loop/#post-1820275)
 * I guess the date could be changed around before the query.
 * What i am trying to do is list all custom posts that have the custom date field
   stating a date after the current date. Basically i have a list of holidays and
   once the departure date for the holiday has passed i no longer need them to be
   listed, the idea being the posts are still there but wont be visable until an
   admin changes the dates for the next time that holiday will take place, then 
   it will re appear in the listing with the ammended date.
 * The holidays come under 4 different custom post types as explained earlier and
   each carries a departure date “ukhol_ddate_meta” (for the ukhol post type).
 * Hope that makes sense.
 * I have all my custom post types defined in my function.php file and my post list
   is in my index.php file, i have a line of code in my function.php which allows
   posts, ukhol, holabroad, specevent & daybreak post types to be visible when viewing
   the index.php, which works fine, i just need to ommit any holidays thats departure
   date has passed.
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/custom-post-queryfilter-loop/#post-1820277)
 * If the date fields are in yyyy-mm-dd format, the posts can be listed with a query
   like this (I can’t test this so watch for typos):
 *     ```
       $today = date('Y-m-d');
       $args = array(
          'post_type' => 'ukhol',
          'meta_key' => 'ukhol_ddate_meta',
          'meta_value => $today,
          'meta_compare' => '>',
          'posts_per_page' => -1
       );
       query_posts($args);
       if (have_posts()) {
          while (have_posts()) {
             the_post();
             //  Put code here to display the poat
          }
       } else {
          // Put code here for 'no posts found'
       }
       ```
   

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

The topic ‘Custom Post Query/Filter Loop’ is closed to new replies.

## Tags

 * [custom post](https://wordpress.org/support/topic-tag/custom-post/)
 * [field](https://wordpress.org/support/topic-tag/field/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/custom-post-queryfilter-loop/#post-1820277)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
