Overriding wp_get_archives() apply_filters()

A WordPress filter is a function that takes in a string, array, or object, does something to it, and returns that filtered string, array, or object.

So what you want to do is turn "WHERE post_type="post" AND post_status="publish"" into "WHERE post_type="post" OR post_type="events" AND post_status="publish"". That is fairly straightforward.

From the looks of things, the getarchives_where filter accepts two arguments. So you’ll hook onto the filter like so:

add_filter( 'getarchives_where', 'my_fancy_filter_function', 10, 2 );

Then you need to write a function that takes in two parameters, filters them, and returns a string:

function my_fancy_filter_function( $text, $r ) {
    return "WHERE post_type="post" OR post_type="events" AND post_status="publish"";
}

Now, this function will take in any input, but it will always return the string for the filter you specified. There are much more advanced ways to add query parameters, but this will accomplish exactly what your question is asking.

Leave a Comment