Forums

PLZ HELP What am I doing wrong? How would I do this? Trying to filter posts! (5 posts)

  1. arkinsokin
    Member
    Posted 2 years ago #

    Ok so I want to be able to filter posts through a function.
    I suppose I need a Action Hook that is after the posts are loaded, but before anything is displayed (as I may set cookies)

    So I am using the action hook "init", which "Runs after WordPress has finished loading but before any headers are sent"

    My questions are:
    -is this the right action hook to use?
    -how can I access wp's loaded posts. For example I would like to loop through all posts and (for example) check if each post is in category X. If it is, I would like to remove it from wp's loaded posts.

    And so by doing this in my plugin, it is my belief that WP should only loop through the remaining posts once it gets into "The Loop". Am I doing this right? Please help me and answer my questions, I have been desperately struggling with this for the past week, and I really appreciate any help. Thanks

  2. raskull
    Member
    Posted 2 years ago #

    So you're saying that filtering them at the loop is too late for your purposes? Then I still got nothin' (but a bump) for you. :`\

  3. arkinsokin
    Member
    Posted 2 years ago #

    aaaa! I just figured out a better way.
    I am just going to use:
    <?php query_posts($query_string . '&id=-3,-8'); ?>\
    right before "the loop"

    Going to dynamically generate the -ID from my variable... I think...

    would this work?

  4. arkinsokin
    Member
    Posted 2 years ago #

    Ok so I can't figure out which filter hook to use.
    Essentially I want to change/ add to the string value that is used whenever the function query_posts() is called. I want to append something like &'post__not_in' => array(.... Anyone know which filter hook I should use? I can't figure this out! I also see query_vars filter hook, but I have no clue what to do with it!

  5. Mark / t31os
    Moderator
    Posted 2 years ago #

    http://codex.wordpress.org/Plugin_API/Action_Reference

    Try pre_get_posts, or maybe even parse_query ..

    Example of using the pre_get_posts action can be seen in various other threads.
    http://www.google.co.uk/search?q=site%3Ahttp%3A%2F%2Fwordpress.org%2Fsupport+pre_get_posts

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.