Aahhh, it’s a typo, I guess.
There is no parameter called posts__not_in
. It’s called post__not_in
.
So you should change your code to:
function dark_delight_get_related_posts(){
$post = get_post();
$args = array(
'posts_per_page' => 4,
'ignore_sticky_posts' => true,
'post__not_in' => array($post->ID), // post and not posts
);
$categories = get_the_category();
if( !empty($categories) ){
$category = array_shift( $categories );
$args['tax_query'] = array(
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $category->term_id,
),
);
}
return new WP_Query( $args );
}
Related Posts:
- Get current post id in functions.php
- Hiding posts in a list from specified categories
- Change post order random through out the entire WordPress
- How to do set post permalinks using 6 digit random unique function?
- Every second post different class in blog view
- How to check in functions.php if there is data in a WP_Query?
- Related Posts function not working
- Query function not executed between element [closed]
- how to show comments only author which send own posts in wordpress
- Function is printing twice – any suggestions?
- Show all posts from the tags without having to set all of them
- Filters do not work when there are multiple (one works)
- Search by post title and content in wp_query without order
- Hiding Draft Post In Admin
- Exclude category from
- How do I correctly set up a WP-Query to only show upcoming event-posts?
- Setting posts_per_page for taxonomy term template
- Blog post per page setting conflicting with custom WP_Query?
- How to insert 2 args into 1 Wp_Query for a slideshow
- How to exclude latest x posts from a paginated query?
- Setup a custom dynamic post
- Anyway to grab author name and featured image in an embeded in inital array of posts outside of loop?
- How to verify wp user password by sql query in wp? [closed]
- Removing noindex posts from wp_query
- How to display the link (title) and thumbnail post?
- WP Query – Posts Per Page not working in combination with category__in
- Force the “Choose from the most used tags” meta box section to always be expanded
- Show the content that is after the excerpt using child theme
- Ajaxify This Code
- How to allow users to post only in certain category and hide elements from edit page?
- How to filter my search in post if contains a word in title, content or excerpt?
- How to return another post than requested
- Pausing and Resuming WP_Query results
- Can’t get buddypress notifications in front-end; why do I get this error?
- Select only post id and meta value with WP_Query
- Lost draft under all posts and drafts
- Get user categories with most posts in it
- How do I display some posts fully on the homepage, and some as an excerpt only?
- Random ajax load only works with posts_per_page set to -1
- How to : pagination in 3 different custom loops on the same page
- Send post id through ajax and get the post content back
- How safe is renovating $wp_query when doing WP_Query pagination in Page Template
- Exclude the first ‘n’ number of posts of a tag from home page?
- Query posts and return XML
- how to change the number of posts returned in a specific loop without making it global?
- Display post x of y within category
- Force authors to Preview a post before publishing
- WordPress Automatic Filename Changer
- Query Posts With Over 1000 Views
- posts_per_page option limits the number of Gallery items
- List authors with the last post title and order by last post date
- How to order posts by meta_value and title
- wp_query random post
- wp_posts table: safely remove unused columns to save database storage
- Query Posts by Custom Field
- Adding a blog archive with pagination using WP_Query
- How to get Tags with specific post id
- Redirect to another page using contact form 7? [closed]
- Order posts alphabetically: how to set order=asc in mysql query?
- how can i change WP main archives loop to sort by name or title
- Using wp_list_pages() after calling query_posts()
- how to get post order by post id wp_query?
- Possible to alternate between two loops
- Nested WP_Query breaking loop
- WordPress query_posts by tag doesn’t work anymore(?)
- How to display all posts divided/ordered by post date? [closed]
- Why Query is returning empty array?
- How do I extract just the post ID of the first item in whatever WP_Query returns?
- Show post content and title in diferent divs using WP_Query using a loop
- Change all author links in Blog roll
- Why are my paginated posts always returning the same results?
- Ignore latest two posts
- Is it possible to use WP_Query to only pull posts with attachments?
- disable Tab post on nav-menus page (Admin)
- Adding bootstrap classes to video shortcodes
- Show posts by author of membership level (Paid Membership Pro)
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- meta_value timestamp older than now
- Format latest/newest post differently
- Loop doesn’t exclude the specified category in home page
- is_page Funtion for Posts ?
- Get posts with multiple categories
- Do not show children of a category
- Display posts of specific category term
- Post type no single page
- Print out last 3 blogposts
- why the same code got different results when using query_posts in functions.php and index.php
- Query posts by Author and/or by Tag
- Get post meta retrieving wrong value
- Query for first 3 posts to change the look and feel
- Adding a user’s ID behind the tag ref link address
- How to get posts published on the latest date?
- Why posts array is empty?
- The_excerpt() doesn’t parse – how to change that?
- Can’t understand why sometimes a [caption] field appears
- How to only publish posts with image in it
- Page and post loop same template
- Isn’t the way posts are displayed very unefficient?
- Add custom text automatically on each post
- Getting blog pagination to work on page set as front page