[Support request] Error in log, Invalid argument supplied for foreach

Home Forums Support [Support request] Error in log, Invalid argument supplied for foreach

Home Forums Support Error in log, Invalid argument supplied for foreach

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2224264
    maxime

    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.

    #2224345
    Ying
    Staff
    Customer Support

    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!

    #2224359
    maxime

    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.

    #2224461
    Ying
    Staff
    Customer Support

    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?

    #2224474
    maxime

    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.

    #2224491
    Ying
    Staff
    Customer Support

    Keep us updated, I’m very curious πŸ™‚

    #2224503
    maxime

    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.

    #2224536
    Ying
    Staff
    Customer Support

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

    #2224568
    maxime

    Perfect thank you πŸ™‚

    #2224570
    Ying
    Staff
    Customer Support

    You are welcome πŸ™‚

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.