3
votes

I have a custom field (repeater) called "today". In it, i have a "choose the calendar date" subfield.

On a product (woocommerce) i've added 1, 2, 3 or more dates. The return date its like dd/mm and I get the today date to compare with like date(d/m).

The problem is that the loading time is extremly big and i get no results...

What i've tried:

$today = date('d/m');

$args = array(
    'numberposts'   => -1,
    'post_type'     => 'product',
    'meta_query'    => array(
        'relation'      => 'AND',
        array(
            'key'       => 'today_$_mdate',
            'compare'   => '=',
            'value'     => $today
        )
    )
);

    $the_query = new WP_Query( $args );

    if( $the_query->have_posts() ): ?>
    <ul>
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <li>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        </li>
    <?php endwhile; ?>
    </ul>
<?php else:
    echo "No prods"; endif; ?>

<?php wp_reset_query(); 

The repeater field: today

The subfield: date

Why i cant return only the products that has the repeater field subfield set to today's date? It doesnt even return the products.

This is the product handle in WP: http://prntscr.com/kkobbb

This is the custom field set: http://prntscr.com/kkobqo

$today returns `20/08`

New approach:

$today = date('d/m');

$args = array(
    'post_type'      => 'product',
    'posts_per_page' => -1
);

$products = new WP_Query( $args );

if ( $products->have_posts() ) {
  echo '<ul>';
    while ( $products->have_posts() ) {
        $products->the_post();
        if( have_rows('today') ):
            while ( have_rows('today') ) : the_row();
                the_sub_field('mdate');
            endwhile;
        else :
            // no rows found
        endif;
    }
  echo "</ul>";
}

wp_reset_query();

Still huge amount of loading time... and the message Fatal error: Allowed memory size of 536870912 bytes exhausted... in wp-includes/plugin.php on line 179

But atleast, i can filter the products based on its repeater subfield.

1
What is 'Save format' of your date field?Outsource WordPress
@OutsourceWordPress Sorry for the delayed answer. My save/return format is set to custom d/m as in this picture: prntscr.com/kkpcycOzZie
Can you ensure that you are using latest version of ACF and ACF Repeater plugins?Outsource WordPress
It's pro version and its fully updated. No updates required for my plugins.OzZie
Then may be your memory limit very low, try adding this to 'wp-config.php' - define( 'WP_MEMORY_LIMIT', '256M' ); and check again.Outsource WordPress

1 Answers

0
votes

This problem is fixed. From ACF custom field settings just set the repeater field schema to line and not table. For me it was set to table and i had biiiig loading time and crashes.