First replace:
resgister_post_type
with:
register_post_type
to fix the typo.
Secondly replace:
while( $portfolio_query->have_post() ){
with
while( $portfolio_query->have_posts() ){
where you’ve forgotten the plural s.
Note
The reason why calling non-existing methods like:
$portfolio_query->some_non_existent_method()
doesn’t raise a PHP error, is the magic __call
method of the WP_Query
class:
/**
* 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;
}
Without it we would get the expected:
Fatal error: Call to undefined method
WP_Query::some_non_existent_method()
So making typos in WP_Query
method names can be tricky to detect.
I think it might be better to throw an exception instead of returning false
for non-compatible methods:
throw new Exception(
sprintf(
__( 'Call to undefined method WP_Query::%s' ),
sanitize_key( $name )
)
);