WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Filter hook for [request] (5 posts)

  1. AndreSC
    Member
    Posted 6 years ago #

    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? ;-)

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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.

  3. AndreSC
    Member
    Posted 6 years ago #

    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 :-/

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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.

  5. AndreSC
    Member
    Posted 6 years ago #

    thanx

Topic Closed

This topic has been closed to new replies.

About this Topic