My site is using a plugin for displaying an archive widget. It only displays the 'post' post-type. I currently have three different post-types. Looking through the code I found:

$where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish' AND post_date <= now()" );

It seemed like a easy fix. First I changed WHERE post_type = 'post' to WHERE post_type = 'privacy, security' but that didn't work.

Then I did WHERE post_type => array('privacy', 'security') AND post_status = 'publish' AND post_date <= now()" ); but that also didn't work.'

  • 3
    this looks like a SQL question and not a WordPress one. try with WHERE post_type IN ('privacy', 'security') AND post_status...
    – mmm
    May 3, 2017 at 17:05
  • 2
    You could write your own widget or modify the WP_Query via pre_get_posts instead of upending the whole system with hacky SQL modifications? WP themes and plugins should never need to modify SQL to change what a post query fetches
    – Tom J Nowell
    May 3, 2017 at 18:45

1 Answer 1


Couple of things to note; one's a WordPress issue, the other an SQL issue:

For WordPress, instead of editing the plugin files directly, you should use the 'getarchives_where' filter it provides, and change the query there.

For SQL, in order to query for multiple post types, you need a conditional statement in the query, so looking for both 'privacy' and 'security' post types requires an OR can be done with an IN.

WHERE post_type IN ('privacy', 'security') 
    AND post_status = 'publish' 
    AND post_date <= now()

Combine this with the plugin's filter and you get:

apply_filters( 'getarchives_where', function( $where ) {
   return 'WHERE post_type IN ("privacy", "security") AND post_status = "publish" AND post_date <= now()';
    }, 10, 1 );
  • 1
    Note that using this will overwrite any other changes that plugins might have made with this filter
    – Tom J Nowell
    May 3, 2017 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.