• Resolved Astilla VGR

    (@astilla222)


    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

    (@astilla222)

    @quinini have a view on this post please.

    Thread Starter Astilla VGR

    (@astilla222)

    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.