WordPress.org

Ready to get started?Download WordPress

Forums

Cannot break/continue error in taxonomy.php (1 post)

  1. catbegemot
    Member
    Posted 3 years ago #

    I am currently on development versions and have encountered this error since a few days ago. Updated just now and still see this error, so I assume it is still unresolved.

    The full error message I am getting is

    Fatal error: Cannot break/continue 1 level in <path here>/wp-includes/taxonomy.php on line 466

    when trying to create a new post (wp-admin/post-new.php).

    I looked into the code and here's the snippet where the error is occurred:

    function get_objects_in_term( $terms, $taxonomies, $args = array() ) {
    	global $wpdb;
    
    	extract( wp_parse_args( $args, array(
    		'include_children' => false,
    		'field' => 'term_id',
    		'operator' => 'IN',
    		'do_query' => true,
    	) ), EXTR_SKIP );
    
    	$taxonomies = (array) $taxonomies;
    
    	foreach ( $taxonomies as $taxonomy ) {
    		if ( ! taxonomy_exists( $taxonomy ) )
    			return new WP_Error( 'invalid_taxonomy', sprintf( __( 'Invalid Taxonomy: %s' ), $taxonomy ) );
    	}
    
    	$terms = array_unique( (array) $terms );
    //====================== ERROR HAPPENS HERE! ===============
    	if ( empty($terms) )
    		continue;
    //====================== ERROR HAPPENS HERE! ===============
    
    	if ( !in_array( $field, array( 'term_id', 'slug', 'name' ) ) )
    		$field = 'term_id';
    
    	if ( !in_array( $operator, array( 'IN', 'NOT IN' ) ) )
    		$operator = 'IN';
    
    	$taxonomies = "'" . implode( "', '", $taxonomies ) . "'";
    
    	switch ( $field ) {
    		case 'term_id':
    			$terms = array_map( 'intval', $terms );
    
    			if ( is_taxonomy_hierarchical( $taxonomy ) && $include_children ) {
    				$children = $terms;
    				foreach ( $terms as $term )
    					$children = array_merge( $children, get_term_children( $term, $taxonomy ) );
    				$terms = $children;
    			}
    
    			$terms = implode( ',', $terms );
    			$sql = "
    				SELECT object_id
    				FROM $wpdb->term_relationships
    				INNER JOIN $wpdb->term_taxonomy USING (term_taxonomy_id)
    				WHERE taxonomy IN ($taxonomies)
    				AND term_id $operator ($terms)
    			";
    		break;
    
    		case 'slug':
    		case 'name':
    			foreach ( $terms as $i => $term ) {
    				$terms[$i] = sanitize_term_field('slug', $term, 0, $taxonomy, 'db');
    			}
    			$terms = array_filter($terms);
    
    			$terms = "'" . implode( "','", $terms ) . "'";
    			$sql = "
    				SELECT object_id
    				FROM $wpdb->term_relationships
    				INNER JOIN $wpdb->term_taxonomy USING (term_taxonomy_id)
    				INNER JOIN $wpdb->terms USING (term_id)
    				WHERE taxonomy IN ($taxonomies)
    				AND $field $operator ($terms)
    			";
    		break;
    	}
    
    	if ( !$do_query )
    		return $sql;
    
    	return $wpdb->get_col( $sql );
    }

    As you can see the if() statement is not in any loop, therefore continue statement is producing fatal error.

    Simply commenting out the if()...continue structure looks Ok and works in my case, but it will go away with the next update. In any case - this should be looked at.

    Server info:
    PHP Version 5.2.12 running as suphp (CGI)

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 3 years ago by catbegemot
  • This topic is not resolved
  • WordPress version: 3.1-alpha