link between custom post types, custompress

Hi there.

First thanks very much for your great items. They all helped me a lot and i wish your services continue grow up and be very successful. Now as i'm a brand new member here, i will post my first support question and see how the support is going on. Hope it's fantastic as many people said

Okay, let's start

I'm using Custompress with 3 custom post types: BOOK, STUDENT and ORDER. My WP frontend won't be published to visitors. My project is a BOOK management system so WP admin & front-end are only available for employees & managers.

When creating new ORDER, I want to link STUDENT and BOOK items to it. Because i want to know which BOOK and STUDENT belong to that ORDER.

WP 3.1 introduces an easy way to insert link to existing content. It's called "link to existing content" feature. It also provides a search box so we can find items quickly. And it supports custom post type also.

So i think the easiest way to do is.

When adding new ORDER, i have 2 custom field boxes or custom boxes
STUDENT: [text box] [insert button]
BOOK: [text box] [insert button]

When i click insert button, it loads a window like "link to existing content feature", then i can find a STUDENT or BOOK, click on the names i want and they will be shown into text box . :d easy huh?

Hope you guys can help me. I believe it's just a small code and easy to create.

Appreciate for your help!!!!!!

Regards

Henry

  • DavidM

    Hello edragon,

    Welcome to WPMU DEV and many thanks for your kind words!

    Given your scenario, do you think you might find it easier to simply add 1 custom post type called "Order" and then add 2 custom fields, "Student" and "Book", relating to that custom post type?

    With that, you could potentially create the Student and Book custom fields as Drop Down Select Boxes and you could add all your respective students and books as options (assuming there's not too many).

    Doing it this way, you would have your full list of students and books to choose from each time you edit an order and you wouldn't need any custom code to achieve that. It would all be handled completely by CustomPress in the back-end.

    There's a drawback to this method when you have multiple sets of orders (which you might have if you have multiple classes of students). But to deal with that, you might be able to get away with creating a new custom post type for each set of orders (class). Perhaps you could call one of them Orders-2010, then another, Orders-2011. You could potentially use the WordPress export option to backup the past files then.

    Regarding the "link to existing content" feature in WordPress, I believe you're referring to the new internal linking feature which allows you to easily link to other content in WordPress. This feature is meant for linking to urls and not to data itself. It also appears to be limited to the editor and doesn't seem to be built for use with custom fields.

    But perhaps the method I described above might work for you? I'll be looking forward to hearing your thoughts on it.

    Cheers,
    David

  • edragon

    Hi David

    I think it's not a good idea to create STUDENT and BOOK as custom field value. Since we will have new STUDENT and BOOK arrive usually (more than 2000 items). Beside that, we also store their extra infos such as student name, phones, book name, ..etc

    Regarding the "link to existing content" feature. I should clarify that i don't want to link data itself, i just want to show BOOK or STUDENT name, just text. (if have link it will be better but not necessary)

    Imagine that, when i create a new ORDER, what is the easiest way to display BOOK and STUDENT belong to that order?

    ....

    i can click a button near a text box, then it loads a window, i can search a STUDENT name or a BOOK name from 2000 items and click which ones i like, then the name will be displayed into the text box. That's all i need :slight_smile:

    C'mon. Hope someone can help me with this.

  • Ivan

    Hi Henry,

    First I want to clarify that CustomPress is intended to be a GUI for registering post_types, taxonomies and custom fields but the interaction between the different content types is not in the scope of this plugin.

    What you want to achieve is not very complex but I wont categorize it as simple. Here you have 3 different post types and a custom function with which you want to retrieve suggestions for the different posts in each post type.

    I'm using Custompress with 3 custom post types: BOOK, STUDENT and ORDER. My WP frontend won't be published to visitors. My project is a BOOK management system so WP admin & front-end are only available for employees & managers.

    When creating new ORDER, I want to link STUDENT and BOOK items to it. Because i want to know which BOOK and STUDENT belong to that ORDER.

    You can achieve something like that by using the ORDER post ID as the parent for both the BOOK and the STUDENT posts ( check wp_insert_post() for more details ). You can use the "wp_insert_post_data" filter hook or "save_post", "publish_post" or "pre_post_update" action hooks to filter the post_parent where necessary.

    When adding new ORDER, i have 2 custom field boxes or custom boxes
    STUDENT: [text box] [insert button]
    BOOK: [text box] [insert button]

    You can check for the $_POST value of these fields and update them ( the post_parent ) on post ORDER save,update or delete filter or actions.

    When i click insert button, it loads a window like "link to existing content feature", then i can find a STUDENT or BOOK, click on the names i want and they will be shown into text box . :d easy huh?

    This is convenient but it will require some amount of thinking for developing it. It's best if you leave this outside your current scope until you get the other things right.

    If I can help you with anything else let me know.

  • edragon

    Hi Ivan

    Thanks for your answer. As i realize that the "link to existing content" feature in WP 3.1, it worked the way i want. It loads a window and also has search feature, it displays custom post types such as BOOK and STUDENT also. And of course i can click the item i want.

    is there anyway i can get in touch with you directly? As i need to integrate this box into custom field so i hope you can send me a quote for custom development

    Thanks

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.