• Resolved deiwee

    (@deiwee)


    Hello,

    I really struggle with meta_compare parameter. I have posts with ACF Date field [event_starts] and I try to filter events in between two dates (show event by months).

    Filtering by “more” or “less” with one date works, but with two dates it shows all values or no values.

    I try to show all post with ACF Date [event_starts] between October:

    
    $start_date = '20191001'; // October 1, 2019
    $end_date = '20191031'; // October 31, 2019 
    
    echo do_shortcode('[ajax_load_more 
    	post-type="post" 
    	meta_key="event_starts:event_starts" 
    	meta_value="'. $start_date .':'. $end_date .'" 
    	meta_compare=">:lessthan"
    	meta_operator="DATE:DATE" 
    	meta_relation="AND"
    ]');
    

    I get only dates that are 2019-10-31 (but I have dates in between start/end dates), if I use meta_relation=”OR” I get all dates.

    I think problem is with ACF Date format in database and $start_date value. ACF stores values in database without dashes (20191001).

    Maybe someone can help me?

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    hi @deiwee
    Looks like there is a bug in core ALM with lessthan when using multiple meta_query objects.

    I’ve fixed this locally and it will be included in the next release.
    Likely 1 week from now.

    If you need to fix sooner let me know and I can provide the code fix.

    Thread Starter deiwee

    (@deiwee)

    Whow fast support! 🙂

    For now I managed to “fix” this like that:

    
    $start_date = '20191001'; // October 1, 2019
    $end_date = '20191031'; // October 31, 2019
    echo do_shortcode('[ajax_load_more 
    post-type="post" 
    meta_key="event_starts" 
    meta_value="'. $start_date .','. $end_date .'" 
    meta_compare="BETWEEN"
    meta_operator="DATE"
    ]');
    

    I don’t know why but “meta_value” multiple objects work only with comma (examples I found was with colon). Thanks again, I will be waiting for update.

    Regards.

    Plugin Author Darren Cooney

    (@dcooney)

    @deiwee
    Yea, that’s probably a better way anyways.

    Thread Starter deiwee

    (@deiwee)

    Maybe this is same bug, but I get strange sorting problem.

    I have posts with ACF [price], prices goes from 200 – 1048. When I use link to filter values, I always get values >1000 too.

    Example:

    
    <a href="#" 
     data-repeater="default"
     data-post-type="post"
     data-category="" 		 
     data-posts-per-page="8" 
     data-category--not-in="10"
     data-meta-key="price"
     data-meta-value="240"		 
     data-meta-compare="lessthan"
     data-meta-operator="NUMERIC"
     data-order="ASC"
     data-orderby="meta_value_num"		 
    >Price is less than 240
    </a>
    

    I get post with 220, 224, 1001, 1048. If I change posts price field from 1048 to 999, they not appear in filter. Even if I do between 1-200 I still get values more than thousand too. In database values are clean, without any characters. But If I try to get values in short code it works:

    
    echo do_shortcode('[ajax_load_more post_type="post" meta_key="price" meta_value="240" meta_compare="lessthan" meta_type="NUMERIC" order="ASC" orderby="meta_value_num" posts_per_page="4" button_label="More Events"]');
    

    What I missing here? 🙁

    Plugin Author Darren Cooney

    (@dcooney)

    @deiwee I just tested this shortcode with WooCommerce _price custom field and it works.
    I suppose it may be an issue with how your fields are stored.

    Thread Starter deiwee

    (@deiwee)

    Hello, @dcooney, thank you!

    After using:

    
    add_filter('alm_debug', '__return_true');
    

    Found that meta_query type was CHAR. Mistake was in my ahref link here:

    
    data-meta-operator="NUMERIC" // Should be data-meta-type *facepalm*
    

    This mistake trolling from this example Date Comparison
    I thinks:
    meta_operator="DATE:DATE"
    Should be
    meta_type="DATE"

    Thank you again 🙂

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘ACF Date Compare’ is closed to new replies.