[wp-trac] [WordPress Trac] #44319: Trying to get property of non-object PHP notice will occurs if value returned from get_queried_object() is null or empty.
WordPress Trac
noreply at wordpress.org
Wed Jun 6 18:17:47 UTC 2018
#44319: Trying to get property of non-object PHP notice will occurs if value
returned from get_queried_object() is null or empty.
--------------------------+------------------------------------
Reporter: calmiraged88 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 4.9.6
Severity: normal | Keywords: dev-feedback has-patch
Focuses: template |
--------------------------+------------------------------------
In my case, I tryin to set wpquery's "author_name" array value to "" on
Author page, so it'd returning all posts from every users. ''(because for
several reason and development awesomeness, i need this)''
{{{#!php
<?php
function test_pre_get_posts($query) {
if ($query->is_author && $query->is_main_query()) {
$query->set('author_name', '');
}
return $query;
}
add_filter('pre_get_posts','test_pre_get_posts');
?>
}}}
horray, now it's returning the stuffs all i wanted.
but hol'up! now this ugly creature appears: **"Notice: Trying to get
property of non-object in C:\xampp\htdocs\wp-includes\class-wp-query.php
on line ..."**
let's put aside the line of the codes, here is where the problem happened.
on **public function is_author( ... )**:
{{{#!php
$author_obj = $this->get_queried_object();
$author = array_map( 'strval', (array) $author );
if ( in_array( (string) $author_obj->ID, $author ) )
return true;
elseif ( in_array( $author_obj->nickname, $author ) )
return true;
elseif ( in_array( $author_obj->user_nicename, $author ) )
return true;
return false;
}}}
cool stuff, but could you guys give another validation for this thing like
uhh
{{{#!php
if (empty($author_obj->ID))
return false;
}}}
or something above those conditional stuff that returns true? so it
wouldn't produce error notice as I mentioned before.
''please''
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44319>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list