Site logo

Archived topic

Error in log, Invalid argument supplied for foreach

9 replies · Started by maxime on May 18, 2022

Viewing posts 1–10 of 10

Hello,

I have a message error in the file error_log which is:
PHP Warning: Invalid argument supplied for foreach() in /wp-content/themes/generatepress/inc/structure/post-meta.php on line 340

This is what starting at line 340 in the file post-meta.php:

foreach ( $items as $item ) {
		$default_display = true;

		if ( 'comments-link' === $item && is_singular() ) {
			$default_display = false;
		}

I've made some research before writing this post and apparently some have the same problem with this kind of Snippet :

add_filter( 'generate_header_entry_meta_items', function() {
    return array(
        'date',
        'categories',
    );
} );

add_filter( 'generate_footer_entry_meta_items', '__return_false' );

But I don't understand the link between the 2 and before doing anything stupid I prefer to ask.

Thank you.

Hi Maxime,

I don't think the filter will have conflicts with theme templates.

Have you modified any of the theme files at all?

Let me know!

Hello Ying,

I have others code snippet but I don't remember having made any change to the theme templates.
And for the comments section because apparently that's what is present in line 340, the only change I made was to delete the Website case.

the only change I made was to delete the Website case.

I'm not sure what you mean by website case.

Codes in PHP don't stand alone, if there's any error somewhere else, it might affect another line of PHP code.

I tried the snippet you are using, but I don't receive any error warning.

Can you try disable all plugins and custom functions to test if the issue is fixed?

Okay I'm going to try to find where it comes from first. As I saw several post about this I thought it was always coming from the same source.

Keep us updated, I'm very curious :)

Well I deactivated the code snippet I was talking about for 40mn and nothing. As soon as I activated it again I received 3 error

add_filter( 'generate_header_entry_meta_items', function() {
    return array(
        'date',
        'categories',
    );
} );

add_filter( 'generate_footer_entry_meta_items', '__return_false' );

So the Snippet helps me having the category of the article next to the date instead of having it after the sample text.
If there's a way to modify the snippet to keep this design without the error then perfect. If the error isn't important then I can keep it that way. If it's better to just deactivate the Snippet then I'll do it, it's just a design thing about the category tag.

If that's the case, you can just ignore the warning, it won't do any damage to your site.

Perfect thank you :)

You are welcome :)

This archived topic is closed to new replies.