php - Wordpress Post undefined error with Post Date (New to Wordpres Dev)

admin2025-06-04  1

I'm getting an error on a new page with the current Date posted

Notice : Undefined index: ama_text_field_01_2019 on line 57 /

When I checked the error line it says

$options = get_option( 'ama_settings' ); $field = 'ama_text_field_' . get_the_date("m") . '_' . get_the_date("Y"); 57: $options = get_option( 'ama_settings' ); $data = str_replace(' ', '', trim($options[$field]));

To troubleshoot, I changed the Date posted to 2018 instead of 2019. That fixed the error. But going forward this isn't a solution.

Any areas I can look into to fix?

I'm getting an error on a new page with the current Date posted

Notice : Undefined index: ama_text_field_01_2019 on line 57 http://magazine.americanmotorcyclist/6607/quest-completed/

When I checked the error line it says

$options = get_option( 'ama_settings' ); $field = 'ama_text_field_' . get_the_date("m") . '_' . get_the_date("Y"); 57: $options = get_option( 'ama_settings' ); $data = str_replace(' ', '', trim($options[$field]));

To troubleshoot, I changed the Date posted to 2018 instead of 2019. That fixed the error. But going forward this isn't a solution.

Any areas I can look into to fix?

Share Improve this question asked Jan 16, 2019 at 18:50 JthomasJthomas 112 bronze badges 2
  • This code looks plugin or theme specific so it's hard to say how to fix this as it's not clear what you're trying to do. What is the desired result of what you're trying to do? – Swen Commented Jan 16, 2019 at 18:57
  • I figured it was a theme issue. Basically, a new post displays this error when the date is set any time for 2019. 2018 - No error. – Jthomas Commented Jan 16, 2019 at 19:04
Add a comment  | 

1 Answer 1

Reset to default 0

To just get the post date, you can replace that entire section of code with just the get_the_date() function.

To display the article's date, use this code:

<?php echo get_the_date(); ?>

Check out the date format options on the codex page linked above to customize it to your liking, if necessary.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749002584a315526.html

最新回复(0)