WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Apr 04 2011

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]

Written by Travis Smith · Categorized: Genesis, Tutorials

StudioPress Premium WordPress Themes     WP Engine Managed WordPress Hosting

What can I do for you!?

Custom Development

We develop plugins by determining both business/functional and technical requirements, following WordPress development best practices, and using agile methodology to ensure you get the best solution.

Consulting

Have questions? Need a reliable developer to consult? Please contact us today!

Customized Theme

We can customize your theme or child theme, or create a child theme for you based on your needs while enhancing the performance of every individual attribute.

Customized Plugin

We can customize your plugins, extend plugins (e.g., Gravity Forms, Jetpack, Soliloquy) based on your needs ensuring security, performance, and positive business impact.

Contact Us

About Travis Smith

As a WordPress enthusiast, developer, and speaker, Travis writes about what he learns in WordPress trying to help other WordPress travelers, beginners and enthusiasts with tutorials, explanations, & demonstrations.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in