Skip to content

Instantly share code, notes, and snippets.

@gatespace
Last active January 22, 2016 19:33
Show Gist options
  • Select an option

  • Save gatespace/7147747 to your computer and use it in GitHub Desktop.

Select an option

Save gatespace/7147747 to your computer and use it in GitHub Desktop.
[WordPress] デフォルトのアーカイブウィジェットを特定のカスタム投稿タイプの時のみその投稿タイプのアーカイブにする。要「Custom Post Type Permalinks」プラグイン。
/**
* ウィジェット「アーカイブ」にフィルター
* require Custom Post Type Permalinks
*/
add_filter( 'widget_archives_args', 'my_widget_archives_args', 10, 1);
add_filter( 'widget_archives_dropdown_args', 'my_widget_archives_args', 10, 1);
function my_widget_archives_args( $args ){
if ( ! is_admin() ) {
if ( 'blog' == get_post_type() ) {
$args['post_type'] = 'blog';
}
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment