Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
- $post_id = isset( $_GET['post'] ) ? $_GET['post'] : null;
- $characters = [];
- if ( $post_id ) {
- // Get current author.
- $author = get_post_meta( $post_id, 'author', true );
- // Get all characters
- $query = new WP_Query( [
- 'post_type' => 'character',
- 'posts_per_page' => -1,
- 'meta_key' => 'author',
- 'meta_value' => $author,
- 'fields' => 'ids',
- ] );
- $characters = $query->posts;
- }
- $meta_boxes[] = [
- 'title' => 'Demo',
- 'post_type' => 'book',
- 'fields' => [
- [
- 'id' => 'characters',
- 'type' => 'post',
- 'post_type' => 'character',
- 'query_args' => [
- 'post__in' => $characters,
- ],
- ]
- ],
- ];
- return $meta_boxes;
- } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement