Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2. add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
  3.     $post_id = isset( $_GET['post'] ) ? $_GET['post'] : null;
  4.  
  5.     $characters = [];
  6.     if ( $post_id ) {
  7.         // Get current author.
  8.         $author = get_post_meta( $post_id, 'author', true );
  9.  
  10.         // Get all characters
  11.         $query = new WP_Query( [
  12.             'post_type' => 'character',
  13.             'posts_per_page' => -1,
  14.             'meta_key' => 'author',
  15.             'meta_value' => $author,
  16.             'fields' => 'ids',
  17.         ] );
  18.         $characters = $query->posts;
  19.     }
  20.  
  21.     $meta_boxes[] = [
  22.         'title' => 'Demo',
  23.         'post_type' => 'book',
  24.         'fields' => [
  25.             [
  26.                 'id' => 'characters',
  27.                 'type' => 'post',
  28.                 'post_type' => 'character',
  29.                 'query_args' => [
  30.                     'post__in' => $characters,
  31.                 ],
  32.             ]
  33.         ],
  34.     ];
  35.     return $meta_boxes;
  36. } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement