I'm trying to create multiple taxonomies. As follows.....
$taxonomies = $wpdb->get_results( "SELECT * FROM $table_name" );
foreach ($taxonomies as $taxonomy) {
//stuff that defines the taxonomy
register_taxonomy( $taxonomy->singular_name, 'book', $tagArgs );
}
It appears that WP dislikes regestering the taxonomy with $taxonomy->singular_name
. Xdebug givies me the following error.
Notice: Trying to get property of non-object in /home/wpplugin/public_html/wp-includes/link-template.php on line 898
I've tried several diffent things. Converting the object to an array and feeding that to register_taxonomy(), I've tride casting $taxonomy->singular_name as a string and a few other random guessees that yeilded the same result. The only thing that works is putting a quoted string in place of $taxonomy->singular_name which won't fit my needs.
Does any one have any ideas on this?? Thanks Greg
Full code here.....
add_action( 'init', 'create_book_taxonomies', 0 );function create_book_taxonomies() {
global $wpdb;
$table_name = $wpdb->prefix . 'wlc_custom_taxonomy';
$taxonomies = $wpdb->get_results( "SELECT * FROM $table_name" );
foreach ($taxonomies as $taxonomy) {
$enterMeOnce = $taxonomy->singular_name;
$book = $taxonomy->singular_name;
if($taxonomy->singular_name != 'singular-name'){ //exclude the default table row
$resLabels = array(
'name' => _x( $enterMeOnce , 'Post Type General Name' ),
'singular_name' => _x( $enterMeOnce , 'Post Type Singular Name' ),
'menu_name' => __( $enterMeOnce ),
'name_admin_bar' => __( $enterMeOnce ),
'all_items' => __( $enterMeOnce ),
'add_new_item' => __( 'Add New ' . $enterMeOnce ),
'edit_item' => __( 'Edit ' . $enterMeOnce ),
'new_item' => __( 'New ' . $enterMeOnce ),
'view_item' => __( 'View ' . $enterMeOnce ),
'search_item' => __( 'Search ' . $enterMeOnce ),
'not_found' => __( 'No '.$enterMeOnce .' found' ),
'not_found_in_trash' => __( 'No '.$enterMeOnce .' found in trash' ),
'description' => __( $enterMeOnce .' are special posts that are showcased on the '.$enterMeOnce .' page.' ),
);
$resArgs = array(
'labels' => $resLabels,
'public' => true,
'exclude_from_search' => false,
'publcly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-lightbulb',
'capability_type' => 'post',
'meta_box_cb' => true,
'show_admin_column' => true,
'hierarchical' => true,
'has_archive' => true,
//'rewrite' => true,
/*'capabilities' => array(
'manage_terms' => 'manage_resource',
'edit_terms' => 'manage_categories',
'delete_terms' => 'manage_categories',
'assign_terms' => 'edit_posts'
),*/
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'post_format' )
);
register_post_type( $book , $resArgs );
$labels = array(
'name' => _x( $taxonomy->name . ' Categories', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( $taxonomy->name . ' Category', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( $taxonomy->name . ' Categories', 'text_domain' ),
'all_items' => __( 'All Categories', 'text_domain' ),
'parent_item' => __( 'Parent Category', 'text_domain' ),
'parent_item_colon' => __( 'Parent Category:', 'text_domain' ),
'new_item_name' => __( 'New Resource Category', 'text_domain' ),
'add_new_item' => __( 'Add New Resource Category', 'text_domain' ),
'edit_item' => __( 'Edit Category', 'text_domain' ),
'update_item' => __( 'Update Category', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate resource cat names with commas', 'text_domain' ),
'search_items' => __( 'Search Resource Categories', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove resource categories', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used Categories', 'text_domain' ),
'not_found' => __( 'Resource Category Not Found', 'text_domain' ),
'slug' => __( $taxonomy->name . 'category' )
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'has_archive' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => false,
'rewrite' => true,
);
register_taxonomy( $taxonomy->singular_name, array( $book ), $args );
$tagLabels = array(
'name' => _x( 'Writers', 'taxonomy general name' ),
'singular_name' => _x( 'Writer', 'taxonomy singular name' ),
'search_items' => __( 'Search Writers' ),
'popular_items' => __( 'Popular Writers' ),
'all_items' => __( 'All Writers' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Writer' ),
'update_item' => __( 'Update Writer' ),
'add_new_item' => __( 'Add New Writer' ),
'new_item_name' => __( 'New Writer Name' ),
'separate_items_with_commas' => __( 'Separate writers with commas' ),
'add_or_remove_items' => __( 'Add or remove writers' ),
'choose_from_most_used' => __( 'Choose from the most used writers' ),
'not_found' => __( 'No writers found.' ),
'menu_name' => __( $taxonomy->name . ' Tags' ),
);
$tagArgs = array(
'hierarchical' => false,
'labels' => $tagLabels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'writer' ),
);
register_taxonomy( $taxonomy->singular_name, $book, $tagArgs );
}
}
}
Aucun commentaire:
Enregistrer un commentaire