Skip to content

Instantly share code, notes, and snippets.

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 hawkidoki/9ecbb6fc478430a202ed86cf7ea1044d to your computer and use it in GitHub Desktop.
Save hawkidoki/9ecbb6fc478430a202ed86cf7ea1044d to your computer and use it in GitHub Desktop.
<?php
add_action('init', 'hwk_post_type_example_register');
function hwk_post_type_example_register(){
register_post_type('example', array(
'label' => __('Example'),
'has_archive' => __('examples'),
'rewrite' => true,
'public' => true
));
}
// Args: Remove Single View
add_filter('hwk/post_type/example/args/no_single', '__return_true');
// Query: Post All
add_filter('hwk/post_type/example/query/post/all', 'hwk_post_type_example_post_all', 10, 2);
function hwk_post_type_example_post_all($post, $query){
$post->my_terms = false;
if(($terms = get_the_terms($post->ID, 'my_taxonomy')) && !is_wp_error($terms))
$post->my_terms = $terms;
return $post;
}
// Query: Post Single
add_filter('hwk/post_type/example/query/post/single', 'hwk_post_type_example_post_single', 10, 2);
function hwk_post_type_example_post_single($post, $query){
$post->my_meta = false;
if($meta = get_post_meta($post->ID, 'my_meta_key', true))
$post->my_meta = $meta;
return $post;
}
// Query: Archive
add_filter('hwk/post_type/example/query/archive', 'hwk_post_type_example_query_archive');
function hwk_post_type_example_query_archive($query){
$query->set('posts_per_page', -1);
$query->set('order', 'ASC');
return $query;
}
// Query: Single
add_filter('hwk/post_type/example/query/single', 'hwk_post_type_example_query_single');
function hwk_post_type_example_query_single($query){
return $query;
}
// Template: Archive
add_filter('hwk/post_type/example/template/archive', 'hwk_post_type_example_template_archive');
function hwk_post_type_example_template_archive(){
return 'templates/example/archive.php';
}
// Template: Single
add_filter('hwk/post_type/example/template/single', 'hwk_post_type_example_template_single');
function hwk_post_type_example_template_single(){
return 'templates/example/single.php';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment