[wp-hackers] Archive Widget for Custom Post Types?
scribu
mail at scribu.net
Wed Dec 22 22:12:21 UTC 2010
On Wed, Dec 22, 2010 at 11:50 PM, Anca Mosoiu <anca at anca.tv> wrote:
> As per track #13462 (http://core.trac.wordpress.org/ticket/13462) we are
> supposed to use this filter to achieve the result of listing the archives
> for custom post types, but I'm trying to figure out how to make this work
> only when this code is being called from within my widget.
>
> Do I register the filter in my widget class file? Or is there something
> else I'm missing?
>
Yes, you add the filter when displaying the widget and then you should
probably remove it.
Something like this:
class My_Widget {
private $current_instance;
function widget( $instance ) {
...
$this->current_instance = $instance;
add_filter( 'getarchives_where', array($this, 'getarchives_where') );
wp_get_archives();
remove_filter( 'getarchives_where', array($this, 'getarchives_where') );
}
function getarchives_where( $sql ) {
// Do something with $this->current_instance['post_type']
}
}
More information about the wp-hackers
mailing list