Check if a user is logged in using is_logged_in
. If a user is logged in modify the query using pre_get_posts
filtering posts by the current author ID.
if ( is_user_logged_in() ) :
function filter_posts_by_author( $query ) {
global $current_user;
get_currentuserinfo();
$query->set( 'author', $current_user->ID );
}
add_action( 'pre_get_posts', 'filter_posts_by_author' );
// ... loop
else :
echo 'you must be logged in to view this page';
endif;
Related Posts:
- Hook for post and page load
- Custom Posts on Different Pages
- Display “Post 2 of 4” on single post page?
- Making pages also serve as taxonomies? Or give full pages to taxonomies?
- Trying to edit the single page from a Custom Post
- How can I show a custom post type for users in the authors.php file?
- How Can I Set the Post Author of a Post I Just Created With PHP?
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- Allow non-logged in users to see a future post after clicking on a list of future posts
- No Permission to add new Page, Post or CPT with Admin role
- Including link to custom post type in ‘wp_list_pages’ function
- Multiple pages per post (not pagination)
- Can I change my post type to anything and my site still work?
- Restrict category access to specific users/groups. Author always has access
- How to set the mainpage of a custom post type?
- Render a Post or Page using the correct file
- Custom post type title of each author in his own post
- Display author box on just certain category posts?
- Am I mixing up the concept of posts pages and categories?
- How to setup different permlalinks for posts and pages?
- Display custom post counts for author , not default posts
- Does “Custom Post Type” can have page hierarhy option?
- Cannot save pages after migration
- Need to display author’s email id in the “Edit post” field in wp dashboard. How do I do this?
- Delete Post by User
- WordPress Contents Migration
- One Post with different content, depending on a Page
- Cannot use pages created on WP
- Different post types arranged on one page
- How to display data with pagaination on backend?
- WordPress Author Posts Review After Every Change In The Same WordPress Post
- How to Associate Posts with Pages
- Why are my wp urls showing page not found?
- How do I hide single category post on my post page
- Show the same Article Available in Other Categories
- get_attached_media() on author page not working
- Getting posts under the custom post type ui category
- Page vs Custom Post Types Differences/Issues
- Storing posts from query and accessing later via AJAX call
- If post has custom field then display css-class
- Display only one post each WEEK
- List children on child post
- Restrict custom post type from appearing with ?post_types=
- Show custom post type filtered by category
- create parent post using wp_insert_post
- Turn on and off custom post type from admin?
- Missing Posts in Custom Taxonomy List
- Display random posts, but omit the post it is on?
- How do I do this with WordPress? Taxonomies?
- Disable block with taxonomies at post page
- I would like to have different styles for my posts based on the content of each post
- How can i add thumbnails images to particular post (using code not admin pannel) in wordpress
- Showing posts from different categories and from custom post type
- Get latest 3 posts from multiple CPT in one query
- Which post does a taxonomy term belongs to?
- List custom taxonomy specific to one custom post type
- Post image in WordPress not appearing on home page
- Exclude pages in archives results
- How to add a custom-post-type post within another custom-post-type post edit screen using AJAX?
- Meta query for custom post type ignored in main query
- Changing custom type name hides the posts
- Display Ad on Specific Categories
- Make parts of your wordpress website completely built with data from external APIs?
- Hiding posts by other users and non-logged in
- Update Post Meta for a logged in user
- Add custom field to Posts and sort by it
- Add custom post type settings to wordress default posts
- Trouble with CPT Child 404
- Database to page routing API?
- Get related posts of child term of custom post type
- Two Custom Post Types Many to Many Relationship
- Problem with displaying posts in the CPT category
- JS innerhtml changing style when using AJAX
- Show titles, date of all posts on single category page
- Assign same parrent Page to pages AND custom post types
- Side effects of Script and Iframe in post
- Permit users with author role to edit a custom post type
- Allow Static Page Load Dynamic Child Pages
- How to change the post type a theme shows by default?
- URL rewrite add author as base
- Set a checkmark in a category based on a URL-parameter
- Several post types on WP Query by tag and taxonomy
- Update postmeta Parent when post_status child change
- custom post type category count shortcode
- Portfolio Page for Classic Posts
- Add post location with mile radius allowing search
- Get the category from custom post type
- Is it possible to store Custom Post Type data in separate set of tables and still have wp_post class functionality?
- Set up post page like JAMA articles
- Custom Post Slug same as Parents Category Slug
- Shortcode not working with post counter
- Static page determines as home, but it is not
- Edit the author of custom post type
- Changing default ‘posts’ parameters with register_post_type_args
- Admin Column does not populate with data
- Can multiple authors be assigned on a single custom post?
- How to integrate a form (Ninja Form or Contact Form 7) with Custom Post Types?
- Prioritize posts in query by meta keys?
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Show Custom Post Type meta boxes only on Page Edit