Not sure if this is the right place for this.
I have a custom post type “books” that I want to order by a custom date picker field “published”. I’ve set it up via pre_get_posts – but I have a custom date format – I only want to show month and year. Is this possible, or do I have to use the YYYYDDMM format? This code isn’t working (but I couldn’t get the YYYYDDMM to work either. Any help is appreciated!
function books_posts($query)
{
if( is_admin() ) {
return $query;
}
// only modify queries for ‘book’ post type
if( isset($query->query_vars[‘post_type’]) && $query->query_vars[‘post_type’] == ‘book’ ) {
$query->set(‘meta_key’, ‘published’);
$query->set(‘orderby’, ‘meta_value_num’);
$query->set(‘order’, ‘ASC’);
}
}
add_action(‘pre_get_posts’, ‘books_posts’);