[wp-trac] [WordPress Trac] #42878: PHP notice when a post has a term from a "numeric" taxonomy
WordPress Trac
noreply at wordpress.org
Tue Dec 12 14:39:47 UTC 2017
#42878: PHP notice when a post has a term from a "numeric" taxonomy
--------------------------+-----------------------------
Reporter: strategio | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 4.9.1
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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
<?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 `$term` at line 6161 is `null`.
- The root cause is in `WP_Term::get_instance` where 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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42878>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list