I have a number of pages which are automatically generated. I then use a custom settings box to allow users to exchange the content on those pages.
Problem being, I don’t want users to be able to delete these specific pages. One of those pages is the “Disclaimer”. The reason I’m doing this is because I’m creating a multi-site legal blog network and each page must have a disclaimer under US laws.
How do I hide these auto-generated pages (like “Disclaimer,” below) from the dashboard by title, rather than ID?
// If there is no disclaimer page, generate one from its template
$page = get_page_by_title( 'Disclaimer' );
if(!$page)
{
wp_insert_post(array(
'post_name' => 'disclaimer',
'post_title' => 'Disclaimer',
'post_status' => 'publish',
'post_type' => 'page',
'post_author' => 1,
'page_template' => 'page-disclaimer.php',
));
}
You can hide pages using a filter on
pre_get_posts
. That can be done setting'post__not_in'
argument, but that argument need page ids. And you don’t know the id before the page is created.For that reason, tou can run an additional query to retrieve the ids based on the titles, or better on the slugs (i.e. ‘post_name’).
If you want to hide this one page from users in the dashboard you could try use something like this:
Of course you would have to determine your page ID and add it to the array. With this code you can add more pages to the array you wish to hide.