- This topic has 3 replies, 2 voices, and was last updated 8 years, 8 months ago by .
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.
Home › Forums › Free Themes › Magzimum › Exclude featured posts from the blog
Tagged: exclude featured posts, pre_get_posts
Hello, it’s me again 🙂 Sorry if I ask you one more thing but there is something I am trying for days- How can I remove featured posts and more exactly the most recent post of the slider from default posts page? I would like to keep in the slider the most recent post.
(I read that I should exclude the sticky posts from the main Lop using a custom query… 9
Thanks hope in your help 🙂
Hi @scorbelli,
use the pre_get_posts
filter:
function excludePostId($query) {
$postIds = array(
24, 10
);
if (is_category() && is_main_query()) {
set_query_var('post__not_in', $postIds);
}
}
add_action('pre_get_posts', 'excludePostId');
is_category()
will accept a category slug or ID. You can limit which categories the post will be excluded from.
thanks for your reply! I guess that the code you showed me is to be put in function.php
There is a problem though, the post that i hide one day, the next day I would like to be showed-
Actually I found a plugin wp hide post, sadly is not updated (still seems to work) and i think it will do the same thing of the code. it would be easier though to change a post from hidden to displayed while for the code i should change manually the id…is it so?
Thanks again for your reply !
Yes, the coding approach however would be quite manual in that sense and not always feasible until you go ahead and make it to control them through metabox or custom fields.
Nevertheless, you figured it out by installing a plugin which could be easy and handy based on your requirement which is a good thing ! 🙂
Thanks
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |