Support » Plugin: WP Pipes » v1.30 – Broken Category Import

  • Howdy,
    I noticed in release 1.30 you added the ability to grab the categories from RSS feeds to include in new posts. Unfortunately, however, it was incompletely implemented and is broken.

    First and most importantly, there needs to be an option to select whether or not you want to create a new category if one doesn’t exist.

    For instance, if the feed’s post has a category “Announcements” that doesn’t correspond to an “Announcements” post category on the site consuming the feed, the site’s admin should be able to choose whether or not that category is created or to ignore unknown categories.

    As for the functionality being completely broken, if there are multiple categories for a post they get concatenated into a comma delimited string, however the parser for creating posts is looking for a pipe delimited string.

    You can see this if you look at the code in this file:

    			$categories_obj   = $items[ $i ]->get_categories();
    			$categories       = array();
    			if ( count( $categories_obj ) ) {
    				foreach ( $categories_obj as $category ) {
    					if ( $category->get_label() != '' ) {
    						$categories[] = $category->get_label();
    			$row->category   = implode( ', ', $categories );

    If you have the categories “dogs” “cats” “birds” this block of code will get you a string containing “dogs, cats, birds” which is all well and good at this point.

    However, if you look at the code in the file that parses the values into a new post:

    		if ( @$data->category != '' ) {
    			$categories = explode( "|", $data->category );
    			$list_cate  = array();
    			foreach ( $categories as $cats ) {
    				$sub_cat = trim($cats);
    				$term    = term_exists( $sub_cat, 'category' );
    				if ( $term !== 0 && $term !== null ) {
    					$new_cat_id = $term['term_id'];
    				} else {
    					$cat_defaults = array(
    						'cat_ID'               => 0,
    						'cat_name'             => $sub_cat,
    						'category_description' => '',
    						'category_nicename'    => sanitize_title( $sub_cat ),
    						'category_parent'      => 0,
    						'taxonomy'             => 'category'
    					$new_cat_id   = wp_insert_category( $cat_defaults );
    				$post_cate[] = $new_cat_id;

    This line breaks the import because our string of categories (“dogs, cats, birds”) now gets parsed as a single category called “dogs, cats, birds” because it’s not looking for commas:
    $categories = explode( "|", $data->category );

    Updating that to explode on the comma would fix the issue.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘v1.30 – Broken Category Import’ is closed to new replies.