[wp-hackers] where does the custom taxonomy info is kept?

Dion Hulse (dd32) wordpress at dd32.id.au
Sat Apr 7 00:46:50 UTC 2012


register_taxonomy must be called on every page load, the data is
"registered" for the current page load only, and must be called before
anything that needs to use it. The best place is a hook attached to
'init' usually.

The only data which is stored in the database is the actual Terms,
which are stored in the 'terms' table. The relationship between a
Term->Post object is stored in the 'term_relationships' table, and the
relationship linking a term to it's taxonomy is in the 'term_taxonomy'
table - Only the slug of the Taxonomy is stored in the database, in
your case, it would be 'genre' or 'writer' but they'll only be there
if you insert a Term that's actually in that taxonomy, the code you're
using inserts a category only.

See http://codex.wordpress.org/Database_Description#Table:_wp_terms onwards

On 7 April 2012 10:41, Haluk Karamete <halukkaramete at gmail.com> wrote:
> but registered where? in a text file?
>
> I run the code in a stand alone php page, not in some theme's
> functions.php.
>
> the exact page goes like this,
>
> when you say registered? I'm curious to know where it is registered,
> memory?
>
> <?php
>
> error_reporting (E_ALL);
>
>
> $full_path_to_wp_header = "F:\inetpub\wwwroot\... mypath here...
> \wp-load.php";
>
> include ($full_path_to_wp_header);
>
>
>
> define('WP_USE_THEMES', false);
>
> echo bloginfo();
>
> if(0):
> $arg = array('description' => "my description", 'parent' => "");
> $new_cat_id = wp_insert_term("Religion", "category", $arg);
> var_dump( $new_cat_id);
> endif;
>
>  $labels = array(
>    'name' => _x( 'Genres', 'taxonomy general name' ),
>    'singular_name' => _x( 'Genre', 'taxonomy singular name' ),
>    'search_items' =>  __( 'Search Genres' ),
>    'all_items' => __( 'All Genres' ),
>    'parent_item' => __( 'Parent Genre' ),
>    'parent_item_colon' => __( 'Parent Genre:' ),
>    'edit_item' => __( 'Edit Genre' ),
>    'update_item' => __( 'Update Genre' ),
>    'add_new_item' => __( 'Add New Genre' ),
>    'new_item_name' => __( 'New Genre Name' ),
>    'menu_name' => __( 'Genre' ),
>  );
>
>  register_taxonomy('genre',array('book'), array(
>    'hierarchical' => true,
>    'labels' => $labels,
>    'show_ui' => true,
>    'query_var' => true,
>    'rewrite' => array( 'slug' => 'genre' ),
>  ));
>
>  // Add new taxonomy, NOT hierarchical (like tags)
>  $labels = 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' ),
>    'menu_name' => __( 'Writers' ),
>  );
>
>  register_taxonomy('writer','book',array(
>    'hierarchical' => false,
>    'labels' => $labels,
>    'show_ui' => true,
>    'update_count_callback' => '_update_post_term_count',
>    'query_var' => true,
>    'rewrite' => array( 'slug' => 'writer' ),
>  ));
>
>  echo "<p>Done!";
>
> $taxonomies=get_taxonomies('','names');
> foreach ($taxonomies as $taxonomy ) {
>  echo '<p>'. $taxonomy. '</p>';
> }
>
> ?>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list