To show only pages that a user is the author, I use the pre_get_posts
action to alter the query.
add_action( 'pre_get_posts', function ( $wp_query ) {
$user = wp_get_current_user();
global $pagenow;
if ( !empty($user->roles) ) {
// BackEnd AND Entity "Page" AND "any role other than administrator" AND not New post
if ( is_admin() && 'page' == $wp_query->query['post_type'] && !in_array( 'administrator', (array) $user->roles ) && !in_array($pagenow, ['post.php', 'post-new.php']) ) {
$wp_query->set( 'author', $user->ID );
add_filter( 'views_edit-page', '__return_empty_array' ); // To hide filters in top of the list page ( All(X) | Publish(X) | Draft(X) )
}
}
});
Related Posts:
- How does the loop know which post to view?
- Problem with Displaying Custom Theme Page’s Content
- How get the 10 most viewed pages (not post)
- A way to automatically install pages on theme install?
- Get ‘page’ number with infinite scroll
- Get 10 posts from a WP_Query. If less than 10, get the remainder from elsewhere
- Is it possible to manipulate the list of page templates?
- Why doesn’t /2013/01/ properly return January’s archives in archive.php?
- Pages: frontpage.php, home.php, posts page etc
- Posts in multiple Categories different single.php
- Strategy to get post meta for use outside the loop
- Hide certain pages / posts on wp-admin, show custom filter
- Grab the first paragraph of each post
- Single Page WordPress Theme – Using page templates
- wp_insert_post breaks rewrite rules
- A two column loop with one lead post
- Change loop order via form or link (jquery, not URL)
- First post of each category
- Is there any need to use both wp_reset_postdata and wp_reset_query together?
- query posts in wordpress
- Getting Permalink within the loop
- the_excerpt() not showing manual excerpt for Pages
- the_content() in single-{post-type}.php problem
- How to highlight the current page in the nav menu?
- Remove specific published page when theme deactivated
- How can I prevent posts with no title showing up in my query?
- How can I use the WordPress Loop and Pagination in multiple instances but different scenarios throughout my site?
- Migrating to WordPress – but how will it do “structured” data?
- Previous and Next links not populating, have I missed something?
- How to code custom special page
- Twenty Seventeen Pages Loop
- How to add custom meta box when you have a custom page template file
- How to track a users last visited page?
- If user is logged in and has a role echo statement
- WordPress Load Only Page Text
- How to add pages in wordpress using codes?
- Pagination fuction in shortcode always displays on top
- Injecting pre-defined text from custom page template to editor
- Theme development: menu links a tabbed page with page jumps
- Retrieve WordPress’ the_content() with jQuery
- Exclude subcategory from wp_query
- Style first 3 posts differently with WP_Query [duplicate]
- WP_Query not getting all posts, just tagged posts
- Custom theme template files
- first excerpt fine, subsequent post excerpts shift to the right instead of displaying vertically [closed]
- Pagination and multiple loops
- Parent/Child pages
- How can I sort my loop based on meta data, using a form?
- List categories of a post hierarchically?
- Exclude parent categories from the_category() within the loop
- get_the_terms() returning wrong results inside of loop
- WordPress Animation Adjustments
- How do I open a post in a custom page in wordpress?
- Add class every 4 post like , class_1, class_2, class_3, class_4 and class_1, class_2, class_3, class_4
- How do I make my terms for each product display via foreach loop? (woocommerce)
- WordPress Insert ads after every 5th post
- White screen of death on index.php page 3 and above?
- WordPress theme files Organization
- Infinite loop when nesting have_posts()
- Local variable name in setup_postdata()
- Loop is breaking my theme. How can I fix?
- Pages not displaying as sections on static page
- How to show metabox on page if it is using a template
- makeing a terms of use page that is part of the theme
- my ajax wont sent the data, please correct my code
- Creating a theme just to deploy a single page
- control posts order by select option
- Why content is not adding for each blog post
- WordPress Twenty-Fourteen: How to Remove Home Page Header Image from Other Pages
- Alter theme pages on language switch
- wp_editor some functionality not working on custom theme
- Display content on Single page
- One-Page WordPress Template
- How to create multiple pages in a client theme?
- How can I display and excerpt of all pages with a meta_key and meta_value on index.php?
- Advantages/Disadvantages Using Theme Editor Instead of Pages
- Best way to allow for extended use of WordPress functions inside single.php
- Can you create a custom page with content in the center already defined?
- how to make a new page affected by a theme’s index.php layout?
- Conditional loop based on current page
- Loop through all posts, show attachment if there
- Suppress the_content filter in a nested loop
- Tags interfering with next_post_link();
- Simple loop with shortcode rendering problem
- How can I change the title of the Home link in the navigation bar?
- How to close open divs in post loop
- The normal loop with different styles doesn’t work in search.php
- Checking conditionals
- The content not wrapped in paragraph tags with get_page_by_title()
- Standard Way To Do Custom Work Within A Page?
- issue displaying variations in custom template using WPeC 3.8.9.2
- All post ids are the same after this query but rewind_posts() does not seem to work here?
- Not Found when using activity stream as front page with BuddyPress
- Why does the first loop take arguments from the second loop?
- have_posts() return false on single post
- How to defeat “Blog pages show at most __ posts” setting in the loop?
- How do I get information about a page, such as featured image, except, and title?
- Display Page featured Image as well as Posts featured Image
- WordPress Loop with Custom Post Type for Bootstrap Accordion [closed]
- Why am I getting posts back when I shouldnt