Home › Forums › General Issues › sort custom posts by time from repeater
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
The topic ‘sort custom posts by time from repeater’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.