#29109 closed defect (bug) (invalid)
Problem found with wp-includes/posts.php
Reported by: | LewisCowles | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.9.1 |
Component: | Posts, Post Types | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description
Warning Raised
Invalid argument for foreach line 1350 of wp-includes/post.php
using
ubuntu14.04
Apache 2.4.6
MySQL 5.5
PHP Version 5.5.9-1ubuntu4.3 FPM
Writing a new theme, noticed this from go with only a functions.php (bare), index.php, header.php, footer.php and style.css (all pretty much empty apart from theme declaration get_header and get_footer)
Fixed by changing
foreach ( $args->taxonomies as $taxonomy ) { register_taxonomy_for_object_type( $taxonomy, $post_type ); }
To
if(is_array($args->taxonomies) || is_object($args->taxonomies) ){ foreach ( $args->taxonomies as $taxonomy ) { register_taxonomy_for_object_type( $taxonomy, $post_type ); } }
header.php
<!DOCTYPE html> <!--[if lt IE 7]><html class="no-js ie ie6 lte8 lte7"><![endif]--> <!--[if IE 7]><html class="no-js ie ie7 lte8 lte7"><![endif]--> <!--[if IE 8]><html class="no-js ie ie8 lte8"><![endif]--> <!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]--> <head> <meta charset="<?php bloginfo( 'charset' ); ?>"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title><?php wp_title( '|', true, 'right' ); ?> <?php bloginfo( 'blog_name' ); ?></title> <link rel="profile" href="http://gmpg.org/xfn/11"/> <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>"/> <?php wp_head(); ?> <script type="text/javascript"> (function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement) </script> </head> <body <?php body_class(); ?> >
footer.php
<div class="push"></div> </div><!-- end of content before footer --> <footer class="footer txtC"> <br/> <a href="#" target="_blank" class="pull-right"> <img src="/assets/brand.png" /> </a> </footer> <script type='text/javascript'> //<![CDATA[ //]]> </script> </body> </html>
index.php
<?php get_header(); ?> <div class="wrapper"><!-- straight after header --> <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <?php the_content(); wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . 'Pages: ' . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>', ) ); edit_post_link( 'Edit', '<span class="edit-link">', '</span>' ); ?> <?php endwhile; ?> <?php endif; ?> <?php wp_footer(); ?> <?php get_footer(); ?>
functions.php is empty
style.css is empty
This is not my first Wordpress Theme, never encountered this before, I have fixed... Wish you had a github advertised on wordpress.org but if you do I cant find it...
Change History (8)
#2
@
11 years ago
- Component changed from Themes to Posts, Post Types
- Keywords reporter-feedback added
This sounds like a plugin passing an invalid value to the taxonomies
argument of register_post_type()
, which only accepts an array.
Does it still happen with all plugins disabled and a default theme (Twenty Fourteen or Twenty Thirteen) activated?
#3
@
11 years ago
while it does not happen with 2014 or 2013 activated, there are no plugins...
the value it is outputting when output in an else to the fix I posted is "post_tag"
By the way I have included all source code to the theme with this bug
;)
Oh and there are no plugins
#4
@
11 years ago
I can't reproduce it on a clean install with the files you've provided. Is this a child theme?
#5
@
11 years ago
Hi Sergey,
No, not a child-theme, just a start at a new theme... I do not get the problem on wordpress 3.8, or 3.5 either, so I am also testing... Also as it has been pointed out that it should be receiving an array, so I have updated my proposed fix to the below...
if( is_array($args->taxonomies) ){ foreach ( $args->taxonomies as $taxonomy ) { register_taxonomy_for_object_type( $taxonomy, $post_type ); } } else { trigger_error('Invalid input for taxonomies in register_post_type', E_USER_NOTICE); }
I Believe this would be a more suitable piece of code, although I concede that E_USER_NOTICE is my personal preference
What is the value of
$args->taxonomies
?