add_filter() to listings page?

This topic contains 4 replies, has 3 voices, and was last updated by  Paolo 9 years ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #60229

    Torsten Liebig
    Free User
    Post count: 1

    Hi there,

    I’m successfully able to filter widget listings on some custom parameters via

    add_filter('geodir_filter_widget_listings_join', 'sql_join_clause', 10, 2);

    and

    add_filter('geodir_filter_widget_listings_where', 'sql_where_clause', 10, 2);

    While this works fine, I couldn’t find how to add the same filter on the listings and search page/views.

    Is there a hook for filter the default queries as well (as opposed to just the widget queries like above)?

    #60365

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    I’ve asked to the developers to reply.

    They’ll let you know asap.

    Thanks

    #60367

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hello,

    You would just use the standard WordPress filters like we do: https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

    Thanks,

    Stiofan

    #60525

    Torsten Liebig
    Free User
    Post count: 1

    That did the trick. I added the filters to pre_get_posts like so:

    
    
    add_action( 'pre_get_posts', 'add_custom_sql_filters' );
    function add_custom_sql_filters( $query ) {
        if( ! is_admin() && $query->query["post_type"] == "gd_place" ) :
            add_filter( 'posts_join', 'geodir_filter_widget_listings_join', 10, 2 );
            add_filter( 'posts_where', 'geodir_filter_widget_listings_where', 10, 2 );
        endif;
        return $query;
    }

    which works like a charm. Thanks!

    #60582

    Paolo
    Site Admin
    Post count: 31206

    Thanks for sharing and letting us know 🙂

Viewing 5 posts - 1 through 5 (of 5 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount