-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
55 lines (41 loc) · 1.61 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Remove Post Type Slug */
// Modify the permalink structure for specified custom post types
function gp_modify_cpt_post_types( $post_link, $post ) {
$cpt_with_no_slug = array( 'quy_hoach' );
if ( in_array( $post->post_type, $cpt_with_no_slug ) && 'publish' === $post->post_status ) {
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
}
return $post_link;
}
add_filter( 'post_type_link', 'gp_modify_cpt_post_types', 10, 2 );
// Ensure the main query includes custom post types without slugs
function gp_add_cpt_post_names_to_main_query( $query ) {
$cpt_with_no_slug = array( 'post', 'page', 'quy_hoach' );
if ( ! $query->is_main_query() ) {
return;
}
if ( ! isset( $query->query['page'] ) || 2 !== count( $query->query ) ) {
return;
}
if ( empty( $query->query['name'] ) ) {
return;
}
$query_post_types = $query->get( 'post_type' );
if ( ! is_array( $query_post_types ) ) {
$query_post_types = array();
}
$query_post_types = array_merge( $query_post_types, $cpt_with_no_slug );
$query->set( 'post_type', $query_post_types );
}
add_action( 'pre_get_posts', 'gp_add_cpt_post_names_to_main_query' );
/* Add entry meta for custom post type */
// Add support for entry meta in the specified custom post type
add_filter( 'generate_entry_meta_post_types', function( $types ) {
$types[] = 'quy_hoach';
return $types;
} );
// Add support for footer meta in the specified custom post type
add_filter( 'generate_footer_meta_post_types', function( $types ) {
$types[] = 'quy_hoach';
return $types;
} );