I
I
Ivan Dobroslavin2020-07-18 20:31:46
WordPress
Ivan Dobroslavin, 2020-07-18 20:31:46

How to exclude a post in WordPress by its ID?

The post displays the "Related Pages" block. This block shows links to posts that are in the same category as the post itself. I need to exclude the link to this post so that the page doesn't link to itself.
I'm trying to exclude a post of a certain category like this:

$arg = array (
    'cat' => 54, // выводить посты из этой категории
    'post__not_in' => 2197, // исключить конкретный пост
    'posts_per_page' => 10, // сколько постов выводить
    'orderby' => rand // рандомно
);

For some reason, the line does not work, the post (record) IDs are exactly the same as I set. Where is the mistake? post__not_in => 2197

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene Chefranov, 2020-07-18
@Chefranov

Try throwing an array there

$arg = array (
    'cat' => 54, // выводить посты из этой категории
    'post__not_in' => array(2197), // исключить конкретный пост
    'posts_per_page' => 10, // сколько постов выводить
    'orderby' => rand // рандомно
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question