Skip to content

Instantly share code, notes, and snippets.

@gmajoulet
Created February 4, 2013 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmajoulet/4707441 to your computer and use it in GitHub Desktop.
Save gmajoulet/4707441 to your computer and use it in GitHub Desktop.
Wordpress plugin to use tags and category with custom post types
<?php
/*
Plugin Name: Tags search
Description: Permet de rechercher par tag dans tous les post types
Version: 1.0
Author: Gabriel Majoulet
Author URI: http://www.gabriel-majoulet.fr
*/
if(!class_exists('Tag_Rewrite')) {
class Tag_Rewrite
{
function __construct()
{
add_action( 'pre_get_posts', array(&$this, 'parseQuery') );
}
function parseQuery($query)
{
if (is_tag() || is_category()) {
$post_type = array('post', 'news');
$query->set('post_type', $post_type);
}
return $query;
}
}
}
if(class_exists('Tag_Rewrite')) {
$tag_rewrite = new Tag_Rewrite();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment