Skip to content

Commit

Permalink
Template Parts: Support REST API meta queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Apr 24, 2020
1 parent 5be5b29 commit 335376a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/template-parts.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,19 @@ function gutenberg_render_template_part_list_table_column( $column_name, $post_i
echo esc_html( $post->post_name );
}
add_action( 'manage_wp_template_part_posts_custom_column', 'gutenberg_render_template_part_list_table_column', 10, 2 );

/**
* Filter for adding meta query support to `wp_template_part` REST API queries.
*
* @param array $args The query arguments.
* @param WP_REST_Request $request The request object.
* @return array Filtered $args.
*/
function filter_rest_wp_template_part_query( $args, $request ) {
$args += array(
'meta_key' => $request['metaKey'],
'meta_value' => $request['metaValue'],
);
return $args;
}
add_filter( 'rest_wp_template_part_query', 'filter_rest_wp_template_part_query', 99, 2 );
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export default function useTemplatePartPost( postId, slug, theme ) {
{
status: [ 'publish', 'auto-draft' ],
slug,
meta: { theme },
metaKey: 'theme',
metaValue: theme,
}
);
const foundPosts = posts?.filter(
Expand Down

0 comments on commit 335376a

Please sign in to comment.