Classic editor
You can use the filter hook page_attributes_dropdown_pages_args
and set authors
parameter in query arguments.
add_filter( 'page_attributes_dropdown_pages_args', 'se343814_own_post_as_post_parent', 10, 2 );
function se343814_change_post_type_args( $dropdown_args, $post )
{
//
// for which types to apply the filter
if ( $post->post_type != 'page' )
return $dropdown_args;
$dropdown_args['authors'] = get_current_user_id();
return $dropdown_args;
}
Block editor
In the case of a block editor, above solution will not work.
The list of posts that can be set as a parent is retrieved by a REST request, with context
parameter set to edit
.
I do not know if it’s possible to change the request data when initializing the editor, probably there is no such filter.
However, you can use the rest_{$post_type}_query
filter in conjunction with the context
that is set in the request.
add_filter( 'rest_page_query', 'se343814_rest_own_post_as_post_parent' , 10, 2 );
function se343814_rest_query_page_parent( $args, $request )
{
//
// apply filter only when editing the post
if ( ! isset($request['context']) || $request['context'] != 'edit' )
return $args;
if ( empty($args['author']) )
$args['author'] = get_current_user_id();
return $args;
}