Last active
May 10, 2018 14:04
-
-
Save hwkdev/9ecbb6fc478430a202ed86cf7ea1044d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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