Opened 8 years ago
Closed 8 years ago
#42878 closed defect (bug) (wontfix)
PHP notice when a post has a term from a "numeric" taxonomy
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 4.9.1 |
| Component: | Taxonomy | Keywords: | |
| Focuses: | Cc: |
Description
This happens when the taxonomy name is numerical like "123456" for instance.
Steps to reproduce:
- After WP installation, add the following snippet to the theme's functions.php.
<?php function wpmltm_2077_create_taxonomy() { $labels = array( 'name' => _x( '123456', 'taxonomy general name', 'textdomain' ), 'singular_name' => _x( '123456', 'taxonomy singular name', 'textdomain' ), ); $args = array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'xyz' ), ); register_taxonomy( '123456', array( 'post' ), $args ); } add_action( 'init', 'wpmltm_2077_create_taxonomy' );
- Go to Posts -> 123456 and add a new term "Test term".
- Add a new post with the term "Test term" for taxonomy 123456 and click on "Publish".
- Go to Posts
=> The PHP notice below is thrown.
( ! ) Notice: Trying to get property of non-object in wp-includes\post.php on line 6161
Call Stack
# Time Memory Function Location
1 0.0057 466920 {main}( ) ...\edit.php:0
2 0.4055 25649896 WP_Posts_List_Table->prepare_items( ) ...\edit.php:180
3 0.4055 25649968 wp_edit_posts_query( ??? ) ...\class-wp-posts-list-table.php:136
4 0.4069 25658096 wp( ??? ) ...\post.php:1073
5 0.4069 25658120 WP->main( ??? ) ...\functions.php:960
6 0.4097 25683376 WP->query_posts( ) ...\class-wp.php:715
7 0.4097 25683440 WP_Query->query( ??? ) ...\class-wp.php:599
8 0.4097 25683384 WP_Query->get_posts( ) ...\class-wp-query.php:3222
9 0.4234 25851048 wp_queue_posts_for_term_meta_lazyload( ??? ) ...\class-wp-query.php:3002
*Debugging:*
- The actual value of
$termat line 6161 isnull. - The root cause is in
WP_Term::get_instancewhere we have a strict comparison between the taxonomy name. On one side, we have an integer and on the other side we have a numerical string.
This is because the taxonomies are stored in an array and the key is the taxonomy slug (which can be numerical).
Here's PHP doc http://php.net/manual/en/language.types.array.php:
Strings containing valid decimal integers, unless the number is preceded by a + sign, will be cast to the integer type. E.g. the key "8" will actually be stored under 8. On the other hand "08" will not be cast, as it isn't a valid decimal integer.
Change History (2)
#2
@
8 years ago
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
I don't think using a numeric taxonomy slug is going to be expected or run into in real world usage.
We could forbid numeric taxonomy slugs (like we do with empty, or >32char ones), but I'm not sure that's worth actual effort.
I'm going to close this as wontfix but other committers are free to re-open it.
I had a look at the documentation and now I am not sure this is really an issue.
It says:
Does this mean we cannot use numbers in the taxonomy name?
Note: We detected this issue because we had a failing test and it turned out because of a numeric taxonomy name. I am not sure this is likely to happen in the real world.