Skip to content
bainternet edited this page Jun 15, 2012 · 1 revision

#Input Field

To add a Posts field to your metabox simply use the addPosts method of the metabox object:

$my_meta =  new AT_Meta_Box($config);
$my_meta->addPosts('posts_field_id',array('post_type' => 'post'),array('name'=> 'My Posts '));

Method arguments:

  • ID: field id (string)
  • options: (mixed|array)
    •  '_post_type_' =>  post type name, 'post' (default) 'page' or any custom post type (string) optional
      
    •  '_type_' =>  how to show posts? 'select' (default) or 'checkbox_list' (string) optional
      
    •  '_args_' =>  arguments to query posts, see http://goo.gl/is0yK default ('posts_per_page' => -1) (array) optional
      
  • args: (mixed|array)
    •  '_name_' =>  field name/label, (string) optional
      
    •  '_desc_' =>  field description, (string) optional
      
    •  '_std_' =>   default value, (string) optional
      
    •  '_style_' => custom style for field, (string) optional
      
    •  '_validate_func_' => validate function name, (string) optional
      
  • reapeater: When adding this field to a repeater block set to true (default false)

Get Field Data:

The Posts field stored the selected post id in the database so to echo out the post id use:

$saved_data = get_post_meta($post->ID,'posts_field_id',true);
echo $saved_data;

Clone this wiki locally