Opened 6 years ago
Closed 5 years ago
#46420 closed defect (bug) (fixed)
Warnings on front-end when trying to display the archive for a non-existent term of a custom taxonomy
Reported by: | zaantar | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.3 | Priority: | normal |
Severity: | minor | Version: | 5.1 |
Component: | Taxonomy | Keywords: | good-first-bug has-patch needs-testing dev-feedback |
Focuses: | template | Cc: |
Description
Steps to reproduce the issue:
- Clean site with a Twenty Seventeen theme (but it happens with other themes as well)
- Disable permalinks.
- Register a custom taxonomy (for example, "kind") and create a term ("k1").
- Open this malformed URL in the browser (replace "localhost" if appropriate, of course): http://localhost/?kind=,k1 - note that the term must be valid in order for the issue to occur.
- Observe the warning:
Notice: Trying to get property of non-object in /var/www/html/wp-includes/general-template.php on line 2795 Call Stack # Time Memory Function Location 1 0.0140 363912 {main}( ) .../index.php:0 2 0.0862 365080 require( '/var/www/html/wp-blog-header.php' ) .../index.php:17 3 1.0117 5400536 require_once( '/var/www/html/wp-includes/template-loader.php' ) .../wp-blog-header.php:19 4 1.0221 5485576 include( '/var/www/html/wp-content/themes/twentyseventeen/archive.php' ) .../template-loader.php:77 5 1.0221 5485576 get_header( ??? ) .../archive.php:13 6 1.0221 5485952 locate_template( ???, ???, ??? ) .../general-template.php:41 7 1.0227 5486048 load_template( ???, ??? ) .../template.php:653 8 1.0234 5486480 require_once( '/var/www/html/wp-content/themes/twentyseventeen/header.php' ) .../template.php:704 9 1.0263 5495688 wp_head( ) .../header.php:22 10 1.0263 5495688 do_action( ???, ??? ) .../general-template.php:2668 11 1.0264 5496064 WP_Hook->do_action( ??? ) .../plugin.php:465 12 1.0264 5496064 WP_Hook->apply_filters( ???, ??? ) .../class-wp-hook.php:310 13 1.0673 5829504 feed_links_extra( ??? ) .../class-wp-hook.php:286
The problem is caused by these two lines in wp-includes/general-template.php:
$term = get_queried_object(); $tax = get_taxonomy( $term->taxonomy );
In this case, get_queried_object() returns null and the code is not ready for that.
Attachments (2)
Change History (11)
#2
@
6 years ago
- Keywords needs-patch good-first-bug added
- Milestone changed from Awaiting Review to 5.3
#3
follow-up:
↓ 4
@
6 years ago
- Keywords has-patch needs-testing added; needs-patch removed
It seems to fix your case.
Needs testing :)
#4
in reply to:
↑ 3
@
6 years ago
Replying to truchot:
It seems to fix your case.
Needs testing :)
The particular issue is gone but I am seeing more notices caused by the problem in a different place:
Notice: Trying to get property of non-object in /var/www/html/wp-includes/general-template.php on line 1599
Also, the same thing happens in the Twenty Nineteen theme:
Notice: Trying to get property of non-object in /var/www/html/wp-content/themes/twentynineteen/inc/template-functions.php on line 90
Do you want me to open separate tickets for these?
This ticket was mentioned in Slack in #core by sergey. View the logs.
6 years ago
#8
@
5 years ago
On my attachment, 46420.2.diff, line 1607. You'll see
$title = __( 'Not found' );
I'm not sure if this is the most appropriate $title
in this case. Any feedback would be greatly appreciated.
Related: #29660
Fixed in [25310] for the
is_tag()
check infeed_links_extra()
, but not foris_tax()
, which was introduced later in [36671].The
is_tax()
check should have anif ( $term )
check as well.