[wp-hackers] filtering posts

Nathan Olsen nateomedia at yahoo.com
Sat Jan 20 19:43:17 GMT 2007

add_filter seems to get processed before anything gets
called on a template. So, if my plugin is called on
the template, nothing that I do within my plugin will
effect the add_filter function that I set up. I tried
setting up a global variable and was losing my mind
trying to understand why it wasn't working. I echo'd
the variable and the modified $where statement that
was supposed to be happening through add_filter and
could not understand why my variable was showing up on
it's own but not in the function I had set-up through
add_filter... until I realized that the add_filter had
happened a long time ago. :)

add_filter cannot, it seems, be called from within a
function either. So, I can't have my plugin get called
and then have add_filter run then. That would work
fine! But it's not possible. :(

What needs to happen:

page loads -> plugin called? -> yes -> grab IDs of
posts to display, eliminate all others -> run loop

page loads -> plugin called? -> no -> run loop

Your suggestion of setting up a debugger is a good
one. I've been working on this plugin for a year and
I'm embarrassed to admit I've never used one. :) That
sounds helpful. Thanks.

--- Chris Williams <chris at clwill.com> wrote:

> Set a global variable in your plug-in so later you
> can check it and
> farkle with in the posts_where filter.
> Another option that I use is to create your own
> query_var and pass it as
> a parameter to the page, but from the info you
> provide isn't complete
> enough to understand the exact situation.
> This is not nuclear physics, it's all in the code. 
> Just step through it
> in a debugger and you can see what's happening, when
> filters are called,
> even how WP itself handles similar situations to
> your own.
> One of the best is to watch what happens when
> standard archive queries
> are done (e.g. by date).  This tells you a lot about
> how WP handles this
> itself.  You can then do thou likewise.
> -----Original Message-----
> From: Nathan Olsen
> Subject: Re: [wp-hackers] filtering posts
> Thanks for the reply, but this isn't quite what I
> need. Your plugin relies on knowing what data to
> filter before the page loads. I need to be able to
> decide what data to filter as the page is loading.
> That is, the most important test will be: has my
> plugin been called? If it's been called, alter the
> data; if it hasn't been called, don't alter the
> data.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com

Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.

More information about the wp-hackers mailing list