• Im running a travelling-site with journeys which have a start and ending date. Now these journeys can be several times a year.

    Now I have a single-post with three repeated start and ending dates:

    01.03.2015 - 14.03.2015
    01.04.2015 - 14.04.2015
    01.05.2015 - 14.05.2015

    I want to show my post with its start and ending dates contained in the search date range.

    Searching 01.03.2015 – 01.04.2015 should return one result.
    Searching 01.06.2015 – 01.07.2015 should return no results.

    $reisen_query_args = array(
    'post_type' => 'reisen',
    'post_status' => 'publish',
    'meta_query' => array(
        array(
            'key'       => 'reisezeiten_%_start',
            'compare'   => '>=',
            'value'     => $startdate,
            'type'      => 'DATE'
        ),
         array(
            'key'       => 'reisezeiten_%_end',
            'compare'   => '<=',
            'value'     => $enddate,
            'type'      => 'DATE'
        )
    )

    This works half-way and I cant figure it out why:

    if the search range is 01.03.2015 – 10.03.2015 the post doesn’t show up which is correct

    BUT

    if the range is 05.03.2015 – 16.03.2015 the post shows up which is WRONG because the search starting date must be 01.03.2015 or before to return results.

    AND

    this only happens when Im having repeated fields. As long theres only one date stored 01.03.2015 – 14.03.2015 the query behaves as desired.

    Could someone pls help me with this? I’m searching for weeks now to get this done.

    This is how my query looks like:

    SELECT SQL_CALC_FOUND_ROWS wp410_posts.ID
    FROM wp410_posts
    INNER JOIN wp410_term_relationships
    ON (wp410_posts.ID = wp410_term_relationships.object_id)
    INNER JOIN wp410_postmeta
    ON ( wp410_posts.ID = wp410_postmeta.post_id )
    INNER JOIN wp410_postmeta AS mt1
    ON ( wp410_posts.ID = mt1.post_id )
    WHERE 1=1
    AND ( wp410_term_relationships.term_taxonomy_id IN (29) )
    AND wp410_posts.post_type = 'reisen'
    AND ((wp410_posts.post_status = 'publish'))
    AND ( ( wp410_postmeta.meta_key LIKE 'reisezeiten_%_start'
    AND CAST(wp410_postmeta.meta_value AS DATE) >= '2015-03-02' )
    AND ( mt1.meta_key LIKE 'reisezeiten_%_end'
    AND CAST(mt1.meta_value AS DATE) <= '2015-03-14' ) )
    GROUP BY wp410_posts.ID
    ORDER BY wp410_posts.menu_order ASC
    LIMIT 0, 6
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator James Huff

    (@macmanx)

    I recommend asking at https://support.advancedcustomfields.com/ so the plugin’s developers and support community can help you with this.

    Thread Starter konsument

    (@konsument)

    Yes, I already asked the support but after several emails thats the final answer:

    Honestly, you may have to hire a programmer to write and help you debug the code to solve the issue.

    The code I provided you earlier should work. From my end, it is hard to point out why it is not working.

    Sure Im willing to pay a programmer for this. But I thought this issue is pretty common to ask the community first.

    Unfortunately Im no programmer and besides the ACF-Support only one person on stackoverflow had an idea:

    it’s the multiple rows, in your failed test, it’s matching the start date from the 3rd row. and the end date from the first row …
    … I think the wildcard in the meta_key is the problem, I don’t think you’ll do it with one query, you might need multiple querys, or multiple items in the meta_query array depends on whether there is always three rows, or many more

    When theres no other possibility I sure will hire someone who solve this.

    Moderator James Huff

    (@macmanx)

    Ok, if you do choose to hire someone, please try https://jobs.wordpress.net/ or https://directory.codepoet.com/

    Do not accept any hire offers posted to these forums.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘ACF – get posts with repeated start and ending date’ is closed to new replies.