wordpress - How to fix undefined offset error in post-template.php -
i trying small business wordpress site unable figure out why site generating error. here details:
the error this: undefined offset: -1 in /home/sojour15/public_html/wp-includes/post-template.php on line 278
and here's code post-template.php - starting line 275 - line 278 "$content = $pages[$page - 1];"
if ( $page > count( $pages ) ) // if requested page doesn't exist $page = count( $pages ); // give them highest numbered page exist $content = $pages[$page - 1]; if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) { $content = explode( $matches[0], $content, 2 ); if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) ); $has_teaser = true; } else { $content = array( $content ); }
i have read undefined offset errors , understand means code referring in array doesn't exist not php coder - trying small business - , i'm not sure how fix this. tried hack found somewhere - put '@' in front of line 278. weirdly, hack worked week. it's not working anymore - , better fix code anyway. guidance welcome. thanks. here link 1 of pages happens: https://www.sojournacupuncture.com/treatments-and-services/
$page
having 0. thus, $pages[0-1]
in array, -1 index not exist.
you can put check if $page
empty or 0, should not execute rest of codes. hope works you.
if ( $page > count( $pages ) ) // if requested page doesn't exist $page = count( $pages ); // give them highest numbered page exist // check on $page // if not empty, should execute rest if (!empty($page)) { $content = $pages[$page - 1]; if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) { $content = explode( $matches[0], $content, 2 ); if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) ); $has_teaser = true; } else { $content = array( $content ); } }
Comments
Post a Comment