[wp-hackers] Intervening in $posts derivation in wp-blog-header

ayj & j yllyn at clear.net.nz
Thu Jun 17 03:46:07 UTC 2004


> Perhaps it would be easier to understand what you're trying to do if you
> described it in terms of the ultimate product rather than the process.
> What's the end-goal?

I gave an example in my original post but I can think of many other similar
applications - where something is being done outside of the main wp loop
that affects what you want the loop to do.

So, for example, I have a sticky posts plugin that works off 'custom fields'
. At its simplest users create a post with custom field key 'sticky' and
value '1'. It outputs the sticky posts from its own independent wp
sticky-loop at the top of any appropriate category pages. Straight under
this is the ordinary wp loop from which I want to exclude any of those
sticky posts - which is simple. What is less simple is to get the correct
total number of (non-sticky) posts on that page because $posts has already
been defined - ie you can cut posts out but you cannot easily add the next
one (other than adding a third loop - which seems to me like overkill).

So, in this example, I was wanting to be able to cause wp-blog-header to run
as normal for all page types but to add a further WHERE condition to the
$posts database query that excludes, one way or another, the sticky posts
and hence returns the correct number of posts for that page excluding the
stickies.

Does that make any sense?

A second example would be using an 'exclude' custom field to identify
individual posts that you want to prevent from appearing on the default
index page - but you still want the right number of posts for that page.

In fact thinking a step further, if I could intervene more easily in the
database search query for $posts in wp-blog-header I might not even have
needed an extra sticky posts loop in the first place - if I could force the
order to put the stickies first as well.

So to return to the more general case - wp-blog-header deals very well with
a multitude of possible page request types (eg author requests, date
requests, category requests) which one does not want to modify / repeat for
a special purpose plugins. So it might help to be able to have the ability
to intervene in wp-blog-header by some system of hooks / filters / actions,
particularly those that might influence the database query string.

I don't know if that is any better than my first attempt, but anyway, thanks
for the responses

Andrew





More information about the hackers mailing list