Site icon WP Smith

How to Utilize AgentPress's Settings & Custom Fields in a Separate Post Type

So I wanted to separate out my blog posts from my property posts on a site. In order to do this, I needed to split posts into two post types: post and properties.

First, you need to create your custom post type (and taxonomy, if needed) in your functions.php file.
[php]function wps_custom_posttypetax() {
//Register Custom Post Type
register_post_type('wps_properties',
array(
'label' => 'Properties',
'description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => 'properties'),
'query_var' => true,
'register_meta_box_cb' => 'ap_add_inpost_details_box',
'menu_position' => 20,
'supports' => array('title','editor','excerpt','custom-fields','revisions','thumbnail','author'),
'taxonomies' => array('wps_designs',),
'labels' => array (
'name' => 'Properties',
'singular_name' => 'Properties',
'menu_name' => 'Properties',
'add_new' => 'Add Property',
'add_new_item' => 'Add New Property',
'edit' => 'Edit',
'edit_item' => 'Edit Property',
'new_item' => 'New Property',
'view' => 'View Property',
'view_item' => 'View Property',
'search_items' => 'Search Properties',
'not_found' => 'No Homes Found',
'not_found_in_trash' => 'No Properties Found in Trash',
'parent' => 'Parent Property',
),
)
);

//Register Custom Taxonomy
register_taxonomy('wps_designs',array (
0 => 'wps_properties',
),array( 'hierarchical' => false, 'label' => 'Designs','show_ui' => true,'query_var' => true,'rewrite' => array('slug' => 'design'),'singular_label' => 'Design') );
}
add_action( 'init' , 'wps_custom_posttypetax' );[/php]

The most important line in registering my post type is:

'register_meta_box_cb' => 'ap_add_inpost_details_box',

Once this is done, go to the AgentPress > lib > admin folder and open the file inpost-settings.php. First you will want to comment out the add_action(); on line 12. So, [php]//add_action('admin_menu', 'ap_add_inpost_details_box', 9);[/php]

Find the function ap_add_inpost_details_box which should be around line 13. This function adds the meta_box to the post below the editor. Make one modification: change the post type 'post' to 'wps_properties'.
[php]function ap_add_inpost_details_box() {
add_meta_box('ap_inpost_details_box_1', __('Property Details - Section #1', 'genesis'), 'ap_inpost_details_box_1', 'wps_properties', 'normal', 'high');
if( genesis_get_option('features_2_col1_1', AP_SETTINGS_FIELD) ) {
add_meta_box('ap_inpost_details_box_2', __('Property Details - Section #2', 'genesis'), 'ap_inpost_details_box_2', 'wps_properties', 'normal', 'high');
}
}[/php]

Now you should be ready to use the AgentPress Settings with an another post type; however, it may or may not be used with the PAGE post type as there is one other change that would need to be made in function ap_inpost_details_save. While I haven't tested this, this line:
[php]if(('page' == $_POST['post_type'] && !current_user_can('edit_page', $post_id)) || !current_user_can('edit_post', $post_id ))
return $post_id;[/php]
would need to be changed to:
[php]if((!current_user_can('edit_page', $post_id)) || !current_user_can('edit_post', $post_id ))
return $post_id;[/php]