WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Type UI
[resolved] Link together Custom Post types in admin (2 posts)

  1. abbottr
    Member
    Posted 3 years ago #

    I'm wondering what code I will need in order to add a custom field to a custom post type that will allow me to link it to another custom post type that has already been created.

    For example, the site has 'Spaces' and 'Buildings' as two different custom post types. When adding a new 'space' post for lease or sale, I need to link that space to an existing 'building' post. Basically I want the spaces to live within the buildings almost like a parent, but as two separate custom post types.

    So, the admin field must create an array of all of the existing 'buildings' custom posts, and then allow the user to choose one to link too. I've been messing around with foreach loops, but can't seem to even generate a list of the buildings. Any help is greatly appreciated!!

    http://wordpress.org/extend/plugins/custom-post-type-ui/

  2. abbottr
    Member
    Posted 3 years ago #

    I found a code to loop through pages, and display them as check boxes in the admin, but I need to be able to loop through the 'buildings' custom post types instead.

    foreach ($pages as $page) {
       		if(in_array($page->ID, $value)){
        		    			echo("<span class='check'><input type='checkbox' class='checkbox' value='$page->ID' checked='checked' name='$page->ID' id='$page->ID'/><label for='$page->ID'>$page->post_title</label></span>");
       		}else{
       			echo("<span class='check'><input type='checkbox' class='checkbox' value='$page->ID' name='$page->ID' id='$page->ID'/><label for='$page->ID'>$page->post_title</label></span>");
       		}
       	}

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic