Home Forums Free Themes Magzimum Exclude featured posts from the blog

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #3952
    scorbelli
    Participant

    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 🙂

    #3966
    wensolutions
    Keymaster

    Hi @scorbelli,

    use the pre_get_postsfilter:

    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.

    #3967
    scorbelli
    Participant

    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 !

    #3973
    wensolutions
    Keymaster

    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

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.