Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Test p2p
- */
- add_action('init', 'project_testp2p_init');
- add_action( 'add_meta_boxes', array('project_testp2p_editor', 'register_p2p_meta_box'));
- add_action( 'wp_loaded', 'project_testp2p_wp_loaded' );
- function project_testp2p_init()
- {
- $labels = array(
- 'name' => _x('Sub Posts', 'post type general name'),
- 'singular_name' => _x('Sub Post', 'post type singular name'),
- 'add_new' => _x('Add New Sub Post', 'Event'),
- 'add_new_item' => __('Add New Sub Post'),
- 'edit_item' => __('Edit Sub Post'),
- 'new_item' => __('New Sub Post'),
- 'view_item' => __('View Sub Post'),
- 'search_items' => __('Search Sub Posts'),
- 'not_found' => __('No Sub Posts found'),
- 'not_found_in_trash' => __('No Sub Posts found in Trash'),
- 'parent_item_colon' => '',
- );
- $supports = array('editor', 'revisions', 'comments', 'author', 'custom-fields', 'title');
- register_post_type( 'subpost',
- array('labels' => $labels,
- 'public' => true,
- 'show_in_menu' => true,
- 'supports' => $supports,
- 'hierarchical' => true
- ));
- }
- function project_testp2p_wp_loaded() {
- // Make sure the Posts 2 Posts plugin is active.
- if ( !function_exists( 'p2p_register_connection_type' ) )
- return;
- p2p_register_connection_type(
- array(
- 'name' => 'subpost_to_post',
- 'from' => 'subpost',
- 'to' => 'post',
- 'cardinality' => 'many-to-one',
- 'admin_box' => 'any',
- 'admin_column' => 'any',
- )
- );
- }
- class project_testp2p_editor {
- static function register_p2p_meta_box() {
- add_meta_box( 'project-ace-program-box', 'Link SubPost', array('project_testp2p_editor', 'render_post_meta_box'), 'post' );
- add_meta_box( 'project-ace-program-tab-box', 'Link Post', array('project_testp2p_editor', 'render_program_subpost_meta_box'), 'subpost' );
- }
- static function render_post_meta_box( $post ) {
- p2p_list_posts( p2p_type('subpost_to_post')->get_connected( $post->ID ));
- }
- static function render_program_subpost_meta_box( $post ) {
- p2p_list_posts( p2p_type('subpost_to_post')->get_connected( $post->ID ) );
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement