Skip to content

Custom admin boxes

scribu edited this page Dec 2, 2011 · 10 revisions

If the admin box filters are not enough and you want complete control of the admin interface, you can roll your own admin box.

Here's some code to get you started:

<?php

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

function init_my_connection_type() {
	p2p_register_connection_type( array(
		'name' => 'posts_to_pages',
		'from' => 'post',
		'to' => 'page',
		'admin_box' => 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 ) {
	echo 'This is my box.';

	p2p_list_posts( p2p_type( 'posts_to_pages' )->get_connected( $post->ID ) );
}

Note that you have to handle connection saving yourself.

Clone this wiki locally