Title: Filtering Views Query
Last modified: January 23, 2019

---

# Filtering Views Query

 *  Resolved [Astilla VGR](https://wordpress.org/support/users/astilla222/)
 * (@astilla222)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/filtering-views-query/)
 * Hi All,
 * I have created a Custom post type named ‘Programada’. This custom post type has
   a custom field named ‘Fecha’. It is a date custom field.
 * I want to order my Programada post types by Fecha custom field so I coded this:
 *     ```
       function my_pre_get_posts( $query ) {
   
               $query->set('orderby', 'meta_value');
               $query->set('meta_key', 'fecha'); 
               $query->set('meta_type', 'date'); 
               $query->set('order', 'ASC'); 
   
           // return
           return $query;
   
       }
   
       add_action('pre_get_posts', 'my_pre_get_posts');
       ```
   
 * but im getting this:
    It seems we can’t find what you’re looking for. Perhaps
   searching can help.
 * What could be the issue? Maybe ‘fecha’ is not the real machine name, even when
   in Toolset sais that ‘fecha’ is his machine name?

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

 *  Thread Starter [Astilla VGR](https://wordpress.org/support/users/astilla222/)
 * (@astilla222)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/filtering-views-query/#post-11121178)
 * [@quinini](https://wordpress.org/support/users/quinini/) have a view on this 
   post please.
 *  Thread Starter [Astilla VGR](https://wordpress.org/support/users/astilla222/)
 * (@astilla222)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/filtering-views-query/#post-11307227)
 * It is needed to add “WPCF-” before the name slug.
 * function my_pre_get_posts( $query ) {
 *  $query->set(‘orderby’, ‘meta_value’);
    $query->set(‘meta_key’, ‘wpcf-fecha’);
   $query->set(‘meta_type’, ‘date’); $query->set(‘order’, ‘ASC’);
 *  // return
    return $query;
 * }
 * add_action(‘pre_get_posts’, ‘my_pre_get_posts’);

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

The topic ‘Filtering Views Query’ is closed to new replies.

## Tags

 * [archive.php](https://wordpress.org/support/topic-tag/archive-php/)
 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)
 * [filtering](https://wordpress.org/support/topic-tag/filtering/)
 * [views](https://wordpress.org/support/topic-tag/views/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 1 participant
 * Last reply from: [Astilla VGR](https://wordpress.org/support/users/astilla222/)
 * Last activity: [7 years, 5 months ago](https://wordpress.org/support/topic/filtering-views-query/#post-11307227)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
