0

Am a little new to custom post types, and maybe it's not the right solution to what I am trying to accomplish.

What I am trying to accomplish:

  1. User "Add New Property". This will have option to add image and 15 custom info fields.
  2. All the properties that are added are displayed on a certain page.

I've tried using Advanced Custom Fields, and it works great for ONE page, but is not repeatable.

I've used custom post types to add Property to admin area on the left but am not sure how to add it to one page.

Here is what I have so far:

function create_post_type() {  
    register_post_type( 'my_properties',  
        array(  
            'labels' => array(  
                'name' => __( 'Commercial Properties' ),  
                'singular_name' => __( 'My Property' )  
            ),  
        'public' => true,  
        'menu_position' => 5,  
        'rewrite' => array('slug' => 'properties')  
        )  
    );  
}  

add_action( 'init', 'create_post_type' ); 

function property_taxonomy() {  
   register_taxonomy(  
    'properties',  
    'my_properties',  
    array(  
        'hierarchical' => true,  
        'label' => 'Category',  
        'query_var' => true,  
        'rewrite' => array('slug' => 'MyProperties')  
    )  
);  
}  

add_action( 'init', 'property_taxonomy' ); 

I have the custom fields showing up on the custom post types, but am not sure how to display them all on one page?

2

2 Answers 2

2

What you describe is the typical use case for a custom post type. When you register your post type, set the has_archive argument to true and WordPress will generate a custom post type archive page, which will be the list of all your property posts.

Normally, the number of property posts displayed will use your admin setting for Blog pages show at most, located under Settings > Reading, but you can override that to display all, no matter the number, via the pre_get_posts action:

function property_posts_per_page( $query ) {
    if ( is_admin() || ! $query->is_main_query() )
        return;

    if ( $query->is_post_type_archive( 'property' ) ) {
        $query->set( 'posts_per_page', -1 );
    }
}
add_action( 'pre_get_posts', 'property_posts_per_page' );
4
  • so this would be a hook as well then right?
    – user31344
    Nov 12, 2013 at 0:06
  • instead of using the standard archive page, could I set all these to show up on a certain (chosen) page?
    – user31344
    Nov 12, 2013 at 0:07
  • yes, if you wanted to do it manually you could create a page template and add a custom query to load and output all your property posts.
    – Milo
    Nov 12, 2013 at 0:51
  • you would register your custom post type on the init hook, not sure if that's what you meant by "so this would be a hook as well". the codex page I linked above has a complete example that you could copy/paste to your theme's functions.php and adjust as necessary.
    – Milo
    Nov 12, 2013 at 0:54
0

If you have a content type that has a distinct set of fields - properties in this case - you are looking at custom content types. ACF, while useful for adding fields to existing content types, doesn't define custom types itself.

For creating custom types, I find it useful to start with a plugin; my preference is Pods. Once activated, this facilitates the creation of custom types and defining the fields applicable to said types. In turn, you will be able to create new property instances, all which have the same set of fields as defined by you, but each of which have their own data.

That is the type definition and creation process, however. There is some coding involved to display your content type fields on the front end. That said, the above paragraph will get you started.

1
  • Thanks, I had seen that plugin, but was not sure how to implement :)
    – user31344
    Nov 12, 2013 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.