Home › Forums › Add-ons › Repeater Field › filter custom fields data by date
Hi, I need to filter some custom post by the current date, the code I pasted below works fine, but the only thing is that it does not show the data for all the post_types, only for the one named: ‘tonificar’, I don’t know why, I’ve checked the custom post types names and they are ok. If I remove from the array the ‘tonificar’ post_type, not data is shown, if I set post_type => any only the ‘tonificar’ data is displayed.
Hope you can help me, thanks
<?php
$today= date('Ymd');
$args = array(
'post_type' => array(
'acuaticas',
'dirigidas',
'cuerpomente',
'servicios',
'infantil',
'tonificar'
),
'post_per_page' => 14
);
$the_query = new WP_Query ( $args ) ;
if( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();?>
<?php if( have_rows('schedule')) : while ( have_rows('schedule')) : the_row();
//if the repeater sub-field matches todays date ?>
<li>
<?php if(get_sub_field('dia') == $today) { ?>
<a href="<?php the_permalink(); ?> ">
<span class="data-time"><?php the_sub_field('start'); ?></span>
<span class="data-name"><?php the_title(); ?></span>
</a>
<?php } ?>
</li>
<?php endwhile;
endif; ?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
I don’t see anything wrong with your query. If the post types exist then is should be working, it’s a pretty simple query. My first step would be to see what posts it’s actually returning to see if I’m getting any of the other posts
$args = array(
'post_type' => array(
'acuaticas',
'dirigidas',
'cuerpomente',
'servicios',
'infantil',
'tonificar'
),
'post_per_page' => 14
);
$the_query = new WP_Query ( $args ) ;
echo '<pre>'; print_r($the_query->posts); echo '</pre>';
Hi, John Huebner, thank you for your reply, and yes is a simple query, but it didn’t work, don’t know why but it didn’t. What i did was to changed it a little bit, this way is almost the same but i add categories to every custom post and it worked.
Is giving me another problems in another page that use a similar query, but with the code to print the post i think i will find a solution, so thank you for that!!
<?php
$today= date('Ymd');
$args_cat = array(
'include' => '11,12,13,14,15,17'
);
$categories = get_categories( $args_cat);
foreach ($categories as $category) :
$args = array(
'post_type' => array(
'acuaticas',
'dirigidas',
'tonificar',
'cuerpomente',
'infantil',
'servicios'
),
'category__in' => $category->term_id,
);
$the_query = new WP_Query ( $args ) ;
You must be logged in to reply to this topic.
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!
Plugin boilerplates can do some of the heavy lifting during initial development. We look at four options to speed up your plugin creation. https://t.co/ZtMsdBxAHw
— Advanced Custom Fields (@wp_acf) June 5, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.