If I want to edit an existing post and save it in the WordPress dashboard. After trying to update, it gives the following error.
I use the filter hook for the post edit link.
PHP class file.
\add_filter( 'post_type_link',
\Closure::fromCallable( [ $this, 'format_permalink' ] ),
10,
2
);
/**
* Override the permalink.
*
* @param string $permalink the permalink.
* @param WP_Post $post the post object.
* @return string
*/
protected function format_permalink( $permalink, $post ) {
// This checks if the current post is a child post of the 'degree' post type.
if ( $post->post_type === self::SLUG && ! empty( $post->post_parent ) && $post->post_parent > 0 ) {
$parent_permalink = \get_permalink( $post->post_parent );
if ( $parent_permalink ) {
// For child posts, return the parent's permalink.
return $parent_permalink;
}
}
// For parent posts or other post types, return the original permalink.
return $permalink;
}
Lisäys epäonnistui. Uncaught Error: Attempt to assign property "permalink" on null in /app/vendor/devgeniem/dustpress/classes/query.php on line 267

If I want to edit an existing post and save it in the WordPress dashboard. After trying to update, it gives the following error.
I use the filter hook for the post edit link.
PHP class file.
Lisäys epäonnistui. Uncaught Error: Attempt to assign property "permalink" on null in /app/vendor/devgeniem/dustpress/classes/query.php on line 267