Skip to content

Commit

Permalink
Extend plugin to posts
Browse files Browse the repository at this point in the history
  • Loading branch information
mirekdlugosz committed Jan 12, 2023
1 parent e39c5fd commit d09dcd7
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions ast-template-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@
* Register custom post meta key.
*/
function ast_register_post_meta() {
register_post_meta(
'page',
PAGE_TEMPLATE_META_KEY,
array(
'show_in_rest' => true,
'single' => true,
'type' => 'boolean',
)
);
foreach ( array( 'page', 'post' ) as $post_type ) {
register_post_meta(
$post_type,
PAGE_TEMPLATE_META_KEY,
array(
'show_in_rest' => true,
'single' => true,
'type' => 'boolean',
)
);
}
}

/**
Expand Down Expand Up @@ -72,7 +74,7 @@ function ast_query_vars( $query_vars ) {
function ast_views_edit_page( $views ) {
global $wpdb;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$post_type = $_GET['post_type'];
$post_type = $_GET['post_type'] ?? 'post';

$ast_view_args = array(
'post_type' => $post_type,
Expand All @@ -88,8 +90,10 @@ function ast_views_edit_page( $views ) {
JOIN $wpdb->postmeta AS pmeta
ON posts.ID = pmeta.post_id
WHERE post_status = 'draft'
AND posts.post_type = %s
AND pmeta.meta_key = %s
AND pmeta.meta_value = 1",
$post_type,
PAGE_TEMPLATE_META_KEY
)
);
Expand Down Expand Up @@ -119,6 +123,7 @@ function ast_views_edit_page( $views ) {
}

add_filter( 'views_edit-page', 'ast_views_edit_page' );
add_filter( 'views_edit-post', 'ast_views_edit_page' );


/**
Expand Down

0 comments on commit d09dcd7

Please sign in to comment.