Note that there's no is_admin()
method for the WP_Query
class.
But the interesting part is that PHP will not complain about this:
$query->is_admin()
where $query
is an instance of WP_Query
.
It will just always return false.
This is the reason why (#src):
/**
* Make private/protected methods readable for backwards compatibility.
*
* @since 4.0.0
* @access public
*
* @param callable $name Method to call.
* @param array $arguments Arguments to pass when calling.
* @return mixed|false Return value of the callback, false otherwise.
*/
public function __call( $name, $arguments ) {
if ( in_array( $name, $this->compat_methods ) ) {
return call_user_func_array( array( $this, $name ), $arguments );
}
return false;
}
This is from the PHP documentation:
__call()
is triggered when invoking inaccessible methods in an object context.
The magic __call
method, kicks in when we call the non-existent method is_admin()
.
I assume you're hooking into the pre_get_posts
action.
We can use the is_admin()
check:
add_action( 'pre_get_posts', function( \WP_Query $query )
{
// Only on the front-end
if( is_admin() )
return;
// ... your stuff here ...
} );
or we could use the is_admin
public attribute of the WP_Query
instance:
add_action( 'pre_get_posts', function( \WP_Query $query )
{
// Only on the front-end
if( $query->is_admin )
return;
// ... your stuff here ...
} );
where in fact it's based on the is_admin()
function, in the parse_query()
method (#src):
if ( is_admin() )
$this->is_admin = true;
target everything
? What do you want? please be specific and clear