Check to see if you have a post ID (which you should on a single post page but I am not sure if this is in single.php
or some other template like index.php
) and add that to the $args
if you do.
$args = array( 'numberposts' => 3, 'orderby' => 'rand' );
if (is_singular() && isset($post->ID)) {
$args['exclude'] = array($post->ID);
}
$rand_posts = get_posts( $args );
Reference
http://codex.wordpress.org/Function_Reference/is_singular
http://codex.wordpress.org/Template_Tags/get_posts
http://codex.wordpress.org/Function_Reference/get_pages
Related Posts:
- Restrict custom post type to only site administrator role
- How to force one column layout on custom post type edit page?
- Make featured image required
- previous_post_link() and next_post_link() with a custom post type?
- WordPress REST Create Post of Custom Type
- Limit the post for differents custom post type in the same wp_query
- Assigning a role to a specific custom post type (and ignoring other post types)
- Display posts in random post types
- Custom Post Type by user
- How to create posts (not post template) to be displayed on projects page?
- Multiple Content Block
- Display Custom Post Type in Recent Posts
- IF statement in a do_shortcode
- Slug for standard post post_type
- Make `previous_post_link()` Function Show The Post After Next i.e. Jump A Post
- How do I create an archive page for standard posts?
- Remove parent from custom post type
- Remove All, Published and Trashed Post Views in Custom Post Type
- How can I show a custom post type for users in the authors.php file?
- Blog page showing same content as homepage
- Auto-generated posts not showing in backend (but being counted!)
- How to add post_type=value when editing that post type in the WordPress admin?
- Open Custom Post Type as PDF
- Show custom post type filtered by category
- Get latest 3 posts from multiple CPT in one query
- Which post does a taxonomy term belongs to?
- Meta query for custom post type ignored in main query
- Hiding posts by other users and non-logged in
- Add custom field to Posts and sort by it
- Get related posts of child term of custom post type
- How to change the post type a theme shows by default?
- How can I show 1 featured post in a styled element, and the next few below differently styled
- help
- wp_insert_post wrong post type [closed]
- Can I change my post type to anything and my site still work?
- How to Display Posts From Category Within a Custom Taxonomy?
- How to Make infinite loop of post
- Published post auto change status to pending after 90 days
- How to retrieve all wordpress posts (specific type) inside a function in php?
- display posts of custom post type with custom taxonomy
- Automatically update slug with latest title within custom post type [duplicate]
- Modifying the default post from wordpress
- Post Query not working
- How to filter url on post submission?
- Different structure/content for posts from a custom post type
- creating files for displaying different custom post type posts with paging
- is it possible in a custom post, create custom fields as well whitin?
- custom taxonomy listing returns no posts
- How to controll the Posts post type and general wondering about WP data structure
- Display author box on just certain category posts?
- How to fetch posts that are stored in the different table than (default) wp_posts?
- Am I mixing up the concept of posts pages and categories?
- Building a Data Intensive Website with WordPress
- If/Else child list for Custom Post Type single template within loop?
- Order posts by years
- redirect after submiting post for review
- How to achieve a multi-taxomony layout with posts?
- i need to have a tab with gategory post
- Custom Post type to Woocommerce Product type
- How we can create menu from Appearance > Menu and use as a add-submenu-page for admin menu?
- Enforcing a rigid reusable template structure for similar posts?
- Auto delete pages/posts without views
- Post template not applying on theme (potentially rendering as Page template)
- WordPress retrieving $post based on random key in $_POST
- $_POST from a Meta Box
- minimize wp_query call to database
- Post display in separate page [duplicate]
- Limit posts per page depending on the size of a div?
- Delete Post by User
- Setting up a page to house certain types of posts
- Links Image in “Catalog” Page to Posts
- How to create a discussion post when a custom post is created?
- Only show current category post
- WordPress Contents Migration
- Problem to get the link of the default ‘post’ post type like the orther custom types
- Featured image in custom post is being disabled
- How to set class to “current-page” on the currently viewed single post within a CPT
- Getting wrong ID
- How to make post page unique and show it on home page?
- Custom Post Types and Posts are mixed
- Hook only specific post type
- Custom Post Type permalink not working on new posts
- Query Only Show Text on Posts With Certain Taxonomy Tag
- Query Posts From Multiple Post Types
- Turn post into simple slideshow
- WP Build-In Post selector for CPT
- Query multiple post of which one by taxonomy
- Cannot exclude particular post from loop of custom post type
- How to make a template for a specific post of a custom post type?
- How to hide home title on pages and posts?
- Apply text based styling done for a single post in WPBakery to all posts / create a template out of it [closed]
- How do I hide single category post on my post page
- Front end post or photo or both
- How to create a job post by email parsing? [closed]
- Can WordPress show posts based on a button that the user clicked 2 pages back?
- How to change post cpt with submit button?
- Storing every individual update to the posts being updated over time?
- Change post structure
- display posts, pages and custom post types from another wordpress site
- How to develop Knowledge center in WordPress Website