• Resolved Abd Ur Rehman R.T.

    (@iamabdurrehman)


    Hi,

    I’m trying to use the date field but getting the error when tried to show up the format with get_field():

    Here’s my code:

    $event_date = new DateTime(get_field('event_date'));
                      echo $event_date->format('M')

    I’m getting this error:

    :  Uncaught Exception: DateTime::__construct(): Failed to parse time string (31/12/2018) at position 0 (3): Unexpected character in /Applications/MAMP/htdocs/cs-dev/wp-content/themes/fictional-university-theme/front-page.php:31
    Stack trace:
    #0 /Applications/MAMP/htdocs/cs-dev/wp-content/themes/fictional-university-theme/front-page.php(31): DateTime->__construct('31/12/2018')
    #1 /Applications/MAMP/htdocs/cs-dev/wp-includes/template-loader.php(74): include('/Applications/M...')
    #2 /Applications/MAMP/htdocs/cs-dev/wp-blog-header.php(19): require_once('/Applications/M...')
    #3 /Applications/MAMP/htdocs/cs-dev/index.php(17): require('/Applications/M...')
    #4 {main}
      thrown in 

    When I just use the_field, it works fine.

    Thoughts?

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Fatal error with get_field()’ is closed to new replies.