Support » Plugins and Hacks » Filter hook for [request]

  • Resolved AndreSC

    (@andresc)


    Which filter should one use to modify the MySQL query that WordPress uses to pull posts from the database? ( Ineed to e.g. insert a LEFT JOIN to an extra plugin table, modify the ORDER BY etc.)

    Any examples and pointers much appreciated – as far as ‘filters’ and ‘actions’ are concerned I’m much more proficient in .psd than .php 🙂

    Thanx

    Andre SC

    PS. Hooks are something they have in pop-music right? 😉

Viewing 4 replies - 1 through 4 (of 4 total)
  • There’s lots of hooks you can use, but the main ones for your case are going to be:
    posts_where
    posts_join
    posts_groupby
    posts_orderby
    posts_where_paged
    posts_distinct
    posts_fields
    post_limits
    posts_request
    posts_results

    Probably not all of those though. They’re used for different things at various points. Make your filters output the values you receive and you’ll see how they work.

    Thanx, I didn’t quite ‘get’ how the hooks thing work but I see if I use ‘posts_request’
    and have a function defined as say
    function croer_the_sort($wp_query) {…
    I can modify $wp_query and if I return it, it should work, now just to get my SQL syntac sorted out :-/

    You can use posts_request, of course, but you’d be better off just modifying the specific piece you need to modify. If you want to insert a join, stick a filter on posts_join. That sort of thing.

    thanx

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Filter hook for [request]’ is closed to new replies.