Home Forums Front-end Issues get_field fails get_post_meta works


get_field fails get_post_meta works

  • I have some code in a frontend template that was working but now isn’t…

    The code is:

    $start = get_field(‘start_date’);
    echo $start;

    the result of the echo is: 10/2015

    The expected result (as shown in the database and in the admin) is: 2015/10/22

    The fact that it shows correctly in the admin makes me think a filter is messing it up on the frontend.

    If I instead use the following code:

    $start = get_post_meta($post->ID, ‘start_date’, true);

    Then the result is: 2015/10/22

    Using get_field() cuts off the /22

    This in turn means that my code:

    $start_date = DateTime::createFromFormat(‘Y/m/d’, $start);

    fails due to $start being an invalid format.

  • I just did a quick test on this and it seems to be working correctly on my end. Can you check both the display format and return format for your date field?

  • yeah thing is it’s not a date field, it’s just a standard Text field.

  • In the custom field settings for that field, what is the Return Format set to. It’s possible that the format used to be the same for both edit and return and now they are separate settings.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘get_field fails get_post_meta works’ is closed to new replies.