Skip to content

Custom admin boxes

scribu edited this page Oct 4, 2011 · 10 revisions

If the admin box filters are not enough and you want to roll your own admin box, you can do that:

<?php

add_action( 'init', 'init_my_connection_type', 100 );
add_action( 'add_meta_boxes', 'register_my_meta_box' );

function init_my_connection_type() {
	// Keep a reference to the connection type; we'll need it later
	global $my_connection_type;

	$my_connection_type = p2p_register_connection_type( array(
		'from' => 'post',
		'to' => 'page',
		'show_ui' => false
	) );
}

function register_my_meta_box() {
	add_meta_box( 'my-box', 'My Connected Pages', 'render_my_meta_box', 'post' );
}

function render_my_meta_box( $post ) {
	global $my_connection_type;

	echo 'This is my box.';

	p2p_list_posts( $my_connection_type->get_connected( $post->ID ) );
}

Note that you have to handle connection saving yourself.

Clone this wiki locally