Skip to content

Instantly share code, notes, and snippets.

@bonjmartn
Created June 18, 2016 23:48
Show Gist options
  • Save bonjmartn/bcdb50b60fe3c626a4558c1893e19e49 to your computer and use it in GitHub Desktop.
Save bonjmartn/bcdb50b60fe3c626a4558c1893e19e49 to your computer and use it in GitHub Desktop.
Recipe Functions
// Create Recipe Post Type
add_action('init', 'my_post_type_maker');
function my_post_type_maker() {
$args = array(
/*your custom post type arguments here*/
'labels' => array(
'name' => __( 'Recipes' ),
'singular_name' => __( 'Recipe' )
),
'public' => true,
'has_archive' => true,
'taxonomies' => array('category', 'post_tag'),
'supports' => array( 'title', 'comments', 'editor', 'permalink', 'thumbnail' ),
);
register_post_type('recipe', $args);
}
// Add Recipe Post Type Custom Fields
require_once get_template_directory() . '/inc/recipes.php';
// Make Recipe Post Type Show Up In Categories, Tags
function add_custom_types_to_tax( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
// Get all your post types
$post_types = get_post_types();
$query->set( 'post_type', $post_types );
return $query;
}
}
add_filter( 'pre_get_posts', 'add_custom_types_to_tax' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment