• Resolved Janke

    (@soldier99)


    Hi,
    I instaleld your plugin today on one of my sites and after activating it showns me this error:

    Warning: in_array() expects parameter 2 to be array, string given in /filter-everything/src/Admin/AdminHooks.php on line 136

    I deactivated all other plugins and switched between 4-5 different themes but every time it shown me the same error.

    Please advise how to fix it.

    Thanks,
    J.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author stepasyuk

    (@stepasyuk)

    Hello @soldier99

    Try please to Save changes in the Filters -> Settings -> URL var names tab and let me know if it was helpful.

    Thread Starter Janke

    (@soldier99)

    Unfortunately not. I have no filters created yet and there is this error after activating the plugin

    Warning: in_array() expects parameter 2 to be array, string given in /filter-everything/src/Admin/AdminHooks.php on line 136

    If I create a filter, another one appears on top:

    Warning: Invalid argument supplied for foreach() in /filter-everything/src/Admin/FilterSet.php on line 191

    Now, creating a filter this error message disappears but if I add the filter to the sidebar I see ca 15 similal errors like this one on frontend and frontend site is messed up:

    Warning: array_merge(): Expected parameter 2 to be an array, null given in /filter-everything/src/Entities/TaxonomyEntity.php on line 98

    Thanks,
    J.

    • This reply was modified 2 years, 8 months ago by Janke.
    Plugin Author stepasyuk

    (@stepasyuk)

    Hi @soldier99

    I checked this on my side and it seems you have compatibility issue with some other plugins or custom code that modifies returning value of the WordPrees
    get_option() function.

    You can check it by disabling other plugins one by one. Or check it with another theme.

    Or maybe, although this is less likely you have old PHP version, that doesn’t support [] as new arrays.

    Let me please know, if it was helpful for you.

    • This reply was modified 2 years, 7 months ago by stepasyuk.
    Plugin Author stepasyuk

    (@stepasyuk)

    @soldier99 was your problem with warnings in

    Warning: in_array() expects parameter 2 to be array, string given in /filter-everything/src/Admin/AdminHooks.php on line 136

    and

    Warning: Invalid argument supplied for foreach() in /filter-everything/src/Admin/FilterSet.php on line 191

    solved or it still presents?

    Thread Starter Janke

    (@soldier99)

    There is something weird going on. As I said in my first post I deactivated all plugins except Filter everything and it had this issue.
    I tested in 4 sites, all of them have php 7.4.

    They worked well before but crashed overnight…

    After my last answer I<u> did not change anything.</u> BUT somehow over the other night 2 of the sites came back alive and started to work but 2 of the sites is still having this issue.

    Someone reported today tha he is having the same issue but as I see this post is deleted by the moderator.

    he wrote:

    Notice: Undefined offset: 888 in /wp-content/plugins/filter-everything/src/Entities/TaxonomyEntity.php on line 98
    
    Warning: array_merge(): Expected parameter 2 to be an array, null given in /wp-content/plugins/filter-everything/src/Entities/TaxonomyEntity.php on line 98
    
    Warning: array_unique() expects parameter 1 to be array, null given in /wp-content/plugins/filter-everything/src/Entities/TaxonomyEntity.php on line 98

    I think 888 is a product category ID.

    I resolved editing your plugin, file src/Entities/TaxonomyEntity.php, lines 89~102:

            // Fix for counts for parent, when 'include_children=true'
            // Add posts from children terms to their parents
            // To make correct counts for their parents
            if( ! empty( $this->descendants ) ){
                $parents = array_keys( $this->descendants );
    
                foreach ( $ids as $term_id => $post_ids_array ){
                    if( in_array( $term_id, $parents ) ){
                        foreach ( $this->descendants[$term_id] as $child_term_id ){
                            $ids[$term_id] = array_unique( array_merge( $ids[$term_id], $ids[$child_term_id] ) );
                        }
                    }
                }
            }
    

    With this:

    
            // Fix for counts for parent, when 'include_children=true'
            // Add posts from children terms to their parents
            // To make correct counts for their parents
            if( ! empty( $this->descendants ) ){
                $parents = array_keys( $this->descendants );
    
                foreach ( $ids as $term_id => $post_ids_array ){
                    if( in_array( $term_id, $parents ) ){
                        foreach ( $this->descendants[$term_id] as $child_term_id ){
                            if (empty($ids[$child_term_id])) {
                                continue;
                            }
    
                            $ids[$term_id] = array_unique( array_merge( $ids[$term_id], $ids[$child_term_id] ) );
                        }
                    }
                }
            }
    

    But I don’t know if it can be a correct solution.

    • This reply was modified 2 years, 7 months ago by Janke.
    Plugin Author stepasyuk

    (@stepasyuk)

    The problem:

    Expected parameter 2 to be an array, null given in /wp-content/plugins/filter-everything/src/Entities/TaxonomyEntity.php on line 98

    was a really bug and I already solved it in the latest plugin version 1.2.4
    It was related with case, when a parent filter term had empty (0 posts) child term.

    But this problem:

    Warning: in_array() expects parameter 2 to be array, string given in /filter-everything/src/Admin/AdminHooks.php on line 136

    means that the get_option() function returns something that is not an array (but should be array) It looks like it is something specific for your case. If you disabled all plugins except Filter Everything it means, that data stored in WordPress options is wrong. Maybe updating of these data will help you. (you have to create filters with URL var names and save them)

    I can check this on your site to be sure it is not common problem if you contact me via Facebook or so (the forum rules doesn’t allow to publish my email here, but it’s easy to find my contacts in Google)

    Thread Starter Janke

    (@soldier99)

    Updating the plugin fixed all the issues. Thank you for your quick support.

    Plugin Author stepasyuk

    (@stepasyuk)

    Great! Several stars, for example 5 in review would be not bad for the plugin 😉

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Warning: in_array() expects parameter 2 to be array,’ is closed to new replies.