Contexts / Post Context

Read More: Fieldmanager_Context_Post

Adds a meta box to the new/edit post screen (for any post type), and saves data to post meta.



Additional References


  1. Example 1: Basic Meta Box

    Note that in this example, we're hooking into the action fm_post_post, because we're adding fields to the post post type. If we were adding fields to a custom post type, e.g. event, you would hook into fm_post_event, and the second argument you would add to add_meta_box() would also be 'event'.

    add_action( 'fm_post_post', function() {
    	$fm = new Fieldmanager_TextField( array(
    		'name' => 'demo',
    	) );
    	$fm->add_meta_box( 'Basic Field', 'post' );
    } );
  2. Example 2: Add a meta box to two post types

    Here, we're adding the same field to two post types (sponsor and attendee). In order to do so, we've hooked into both the fm_post_sponsor and fm_post_attendee actions, and we've added the meta box to both post types in the add_meta_box() method call.

    function my_basic_field() {
    	$fm = new Fieldmanager_TextField( array(
    		'name' => 'job_title',
    	) );
    	$fm->add_meta_box( 'Job Title', array( 'sponsor', 'attendee' ) );
    add_action( 'fm_post_sponsor', 'my_basic_field' );
    add_action( 'fm_post_attendee', 'my_basic_field' );