what would be the best way to exclude the current post I am viewing from this recent posts query. Thank You!
<?php
global $post;
if (in_category('top-lists')) {
$myposts2 = get_posts('numberposts=5&offset=0&category=7');
}
else if (in_category('playlists') || in_category('playlistall')) {
$myposts2 = get_posts('numberposts=5&offset=0&category=6,37');
}
else if (in_category('news') || in_category('news')) {
$myposts2 = get_posts('numberposts=5&offset=0&category=95');
}
else {
$myposts2 = get_posts('numberposts=5&offset=0&category=-6,-7,-37,-95,-177');
}
foreach($myposts2 as $post) :
?>
This the
post__not_in
arg should work dandy for you:Add this to your $args
This way you won’t have to deal with getting the current post ID and will potentially avoid errors with getting your ID. The get_the_ID() function just get the ID for you so you don’t have to deal with or do anything.
Add below code in active theme functions.php file