Hey, i want to sort all posts of a custom post type (‘kurse’) by time picker plugin and using time format “HH:mm” as well. My time field is seperated in a repater – from – till – called (‘von’) (‘bis’). So i want to use the (‘von’) field inside the repeater to sort all custom posts (‘kurse’) by start time ((‘von’)).
I tried to use something like that
// args
$args = array(
'numberposts' => -1,
'post_type' => 'kurse',
'meta_query' => array(
array(
'key' => 'zeit',
'value' => 0,
'type' => 'NUMERIC',
'compare' => '>'
)
)
);
but doesen´t work -.-
[the repeater name is (‘zeit’)]
Hi @Speedy-one
ACF does not come standard with a a time picker field, so I can’t provide support for a 3rd party developed field type.
In regards to it being a sub field, you can have a look here as to using sub fields in a WP_Query args:
http://www.advancedcustomfields.com/resources/how-to/how-to-query-posts-filtered-by-custom-field-values/#example-5
Thanks
E
thanks for fast reply… is it possible to sort my custom post type with the date-time-picker?
for example… to get all Courses from monday i use the following… but it is not sorted by time…
<?php
// args
$args = array(
'post_type' => 'kurse',
'posts_per_page' => -1,
'meta_query' => array(
array(
'meta_key' => 'von',
'orderby' => 'meta_value_num',
'order' => 'ASC'
)
)
);
// query
$wp_query = new WP_Query( $args );
// loop
while( $wp_query->have_posts() )
{
$wp_query->the_post(); ?>
<?php $tag_wahl = get_field('tag'); if($tag_wahl == 'Montag'): ?>
<?php the_title(); ?><br>
<?php if(get_field('zeit')): ?>
<?php while(the_repeater_field('zeit')): ?><?php the_field('tag'); ?>´s von <?php the_sub_field('von'); ?> Uhr bis <?php the_sub_field('bis'); ?> Uhr.
<?php endwhile; ?><br><br>
<?php endif; ?>
<?php endif; ?>
<?php }
?>
Hi @Speedy-one
Your last code shows incorrect syntax for the ‘meta_query’. Please read over the WP_Query docs and make sure you are using the correct terms.
Perhaps you can look at using the ‘DATE’ compare?
Maybe your answer would be best found from the developer of the time picker field?
Thanks
E