You could try this, IF the current user is logged in AND not Adminstrator it will pull all posts from the current user, otherwise it should default and show all posts from all users.
<?php
function filter_posts_by_author( $query ) {
if( is_user_logged_in() ) {
if( !current_user_can( 'administrator' ) ) {
global $current_user;
get_currentuserinfo();
$query->set( 'author', $current_user->ID );
}
}
else {
wp_die('Sorry, you do not have access to this page. Please <a href="/#/">sign in</a> to view this page.');
}
}
add_action( 'pre_get_posts', 'filter_posts_by_author' );
?>
Related Posts:
- Custom post type role permissions won’t let me read
- Get the ID of the latest post
- Custom user role cannot see or modify featured image
- Allow user to Edit Posts but not Add New?
- Restrict custom post type view by user role
- List most recent image uploads, but only for specific custom post type
- Confusion with adding meta capabilities to a role after registering a Custom Post Type with corresponding ‘capability_type’ parameter
- Associating an “author” with a custom taxonomy
- Show the First Post from Each of 3 Different Post Types on a Web Page?
- functions.php conditional tag only for custom post type
- How can I get the last posts by user role?
- custom post type upcoming post and past post
- Adding capabilities to default roles
- How to get only one category of custom post type?
- How to query custom post type by term?
- Get random custom posts from a custom post type
- grant a privilege for roles (for example editors) and higher
- Quickest way to get last or oldest post date – WP Query
- Role Capabilities: Add New Ones?
- Prevent authors from creating new posts of specific custom-post-type
- Custom post type capabilities require “create_posts” to access the edit posts list page
- Add custom capabilities to existing custom post type
- allow edit of custom post type but not regular posts?
- using add_role function to make some users to create a selected type post
- Filter the content from a post globally immediately after is fetched from the database
- Combine query_posts() and get_posts() into single query
- Why is my Custom Post Type not showing up after adding capabilities?
- Are there sub-systems in WordPress that would employ data structures beyond CPT that a `get_posts` won’t be able to catch?
- Shortcode for display posts on home page show only one post
- WordPress count child posts of each parent custom post type and use in json array for google maps jquery plugin
- only a certain role has access to a cpt
- Display all post titles of current post type
- Define new user capability for custom post types?
- Users create/join groups
- Edit the author of custom post type
- Allow add new post access to custom post but not wp post for some role
- Create custom post with custom user rules
- Display latest x posts from all categories in Custom Post Type/Taxonomy
- Want to be able to sign up subscribers as authors
- Get only used meta_values
- Custom query for custom post_type
- disable quickedit for specific custom post type user role
- how to associate several authors to a custom post type
- populate array with posts
- Displaying multiple post types on home page
- Conflict between wp_list_pages and get_posts – list pages not displaying
- WordPress: Custom User Role cannot access Custom Post Type | “Sorry, you are not allowed to access this page”
- Select other roles as custom post authors
- Is it possible to use array_walk() to append terms to an array of posts?
- custom hierarchical taxonomy and custom post type list contains surplus posts
- Preventing role reading others posts
- Can’t pull posts of a Custom Post Type based on the custom taxonomy of the CPT
- 4 posts per page from single category
- Enable comments for post when comments meta box removed
- Roles and Capabilities in Custom Post Types
- Query custom posts of logged in user only
- Display a random customposttype2 excerpt in single-custompostype1.php that shares same taxonomy
- How to query custom post types with multiple keys?
- Change user role when user’s first post gets published
- Orderby meta_key/meta_value not displaying anything, am I overlooking anything?
- Clone wp-admin/users.php (Users Admin Page)
- Get_post_custom not fetching value from array wordpress
- Added new role with custom capability. But cannot access the page
- I’m having trouble with Related Product “tax_query” ‘terms’ value
- Conditional editing CPT – using editor’s role and author’s usermeta
- Remove plugin settings from post creation page for a user role
- Get all posts by many custom post types
- Modify default Related Posts Code to Custom Post Type
- Allowing custom role user to edit post assigned to them but don’t let them create new custom type post
- Front-end submitted post is published with admin ID as author
- Query a custom taxonomy in a function to create an csv file
- WooThemes – Vendors / Bookings – Allow Vendors to manage resources
- week days sorting based on starting day
- Front End users account with lots of user Roles (not Woocommerce)
- Get post from Category by Priority
- How can you use a page for a custom post type?
- Running get_posts within get_posts to get children of children
- WordPress get all post with like in terms [duplicate]
- Decrement term in for each
- Allow viewing the edit screen for a post type, but not make/save/publish/update changes
- Custom Post Type only display items created by user
- Add role privileges of the custom post type
- creating different edit screens for different roles
- CPT, Custom User Role and problem with user manager
- one get_posts to return a number of custom posts for each meta value
- How can I give WordPress child custom post type the same title and slug as its parent?
- Display and Allow users to edit their own profiles
- Custom Post Type supports author
- Custom Post Type children and grand-children in one list
- Capability to read user’s own draft post of CPT
- Custom post type & role issues
- Custom role can’t create permalink
- Read-Only custom post type
- How do I correctly query posts from a post ID?
- Custom Plugin w/ Custom Post Types – Custom Posts Are Showing at all Privilege Levels – Is this possible to adjust?
- WordPress Roles
- How to I add count of custom posts listed in a post as a prefix to its title
- How to get permalink of post based on post name?
- WordPress User Role Permissions For Custom Post Type
- remove pagination from a single blog entry