The post__not_in arg should work for you:
$args = array(
'numberposts' => 5,
'offset' => 0,
'category' => 7,
'post__not_in' => array( $post->ID )
);
$myposts2 = get_posts($args);
Related Posts:
- Skipping first 3 posts in wp query
- Exclude ALL posts from sub categories
- Exclude posts with specific meta_value while sorting by a separate meta_value
- Filter Posts by Excluding Categories
- How to set post expiration date and time and move the page to archive after expiration [closed]
- how to get posts ids inside pre_get_posts filter?
- Exclude the first ‘n’ number of posts of a tag from home page?
- Excluding posts not working
- Loop doesn’t exclude the specified category in home page
- How to exclude posts that already appear in the main loop, from the category loop
- How to get post with slug and exclude categories
- Exclude post category in a blog page
- Use posts_where to exclude posts ids from wp_query
- Conditionally exclude post from specific category on home page sidebar?
- Excluding category from post navigation in WordPress?
- Exclude a ‘portfolio’ custom category?
- Stop WP from creating “Sample Page” and “Hello World!” post
- Count how many posts in category
- Custom Single Post By Category
- Post slugs and images cannot have same name?
- Convert custom fields to post categories
- Hide password protected posts in admin
- Most viewed post for the last 2 days using WP_Query
- Adding Post Counts to Menu (Nav) Programmatically?
- This AJAX Code Doesn’t Work – Looking for elegant solution
- Show chart in post using data passed as custom field
- Show One Category on Post
- Show post titles only on the homepage
- Creating new page with pre-defined parent page
- Get all Youtube video’s from posts and embed them on a different page
- How To Add Perfect Apostrophe And Quotation Mark In WordPress Posts?
- Send email to user that his post has been rejected
- How can I highlight syntax like it appears on stackoverflow?
- Custom post type permalinks breaking due to 3.1 bug fix
- wp_insert_post let users post to without login…broke
- Export posts manually selected by end user (not logged in)
- Add Category name to Post Title (h1)
- Blogroll – Different layout for first post
- How to delete old posts’ edits to save space?
- When trashing a post, also trash related comments
- Loop through all product posts?
- Image Insert into posts and pages not working after 3.2.1 update
- Blog Posts not showing title
- How to add Tags Filter in wordpress admin dashboard
- How to display featured image without it appearing in post?
- allow new users to post an article before they sign up [closed]
- Make Post Editor Select Number of Columns To 1 By Default
- Display post category in foreach loop with category link
- Adding custom fields to bbpress reply form
- How To Hide A Post
- Remove Custom Post Type Slug and add Custom Taxonomy to Permalink Structure?
- Why my wp_posts data is so huge?
- Adding a user’s ID behind the tag ref link address
- One post out of more than twenty shows odd picture (from post) in the header
- Benefits to using semantic HTML in post content? [closed]
- custom word in custom permalink structure
- Post filtering is returning blank page
- Using wp_tag_cloud with only posts published in specific year
- Display Featured Posts Grid on Static Page (Gazette)
- how to display today’s most viewed posts order by custom meta “views”
- Keyboard shortcut for headings on safari
- Optimal WP Web App Backend for mobile app development
- WordPress posts have a different URL to the index
- unable to write to the database while uploading images
- Restricting displayed posts to posts from only select authors
- Updating post status via rest api
- How can I create a Survey Form in WordPress that users can fill in and then submit the entire survey contents as a post?
- How to Make my Homepage Display a Single Specific Post?
- unable to display two post per page in wordpress front-page.php
- WP Ajax returning 0, can’t find action
- Anchor links turn to p nbsp p
- Scheduled posts appear as clickable in the front end
- Counting Posts by Category
- show image gallery in archives or category page
- 2 Domains, Same Content, Different Titles?
- Adding wordpress posts using phpmyadmin
- Colorbox not working on native WordPress gallery when gallery is loaded thru AJAX
- Show author bio box
- How can I get post text from all posts on a WordPress news site?
- Use special template for the first post in the loop
- WordPress each user has each content for a page,how to do that?
- Fixing the WP Post Object for Custom Route
- Changing the Category for all posts of an Author
- Posting a comment redirects admin/users to blank page
- Is it possible to have dynamic post id # in add_menu_page()?
- Send/Publish a Post front end
- Hiding menu on mobile only when viewing posts?
- Posts don’t appear on Template Page
- Latest Posts not in the right order
- Howto put advertising as post number 1,2,3 etc
- Last three posts not being put in order by date. How to fix this?
- WordPress sub-posts and permalinks
- limit posts per page
- WordPress Admin Tables in Post View
- Show List of Posts With Comments Open
- When and how will php code in a user made WordPress page be executed?
- Onclick open posts displayed in slider in a popup [closed]
- Listing category and its posts one by one
- Print out one of 2 post category [closed]
- How to get if category has posts?