treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Custom field Wordpress that will auto-populate from others?

  • I am in need of creating a custom post type type that will have a custom field that will pull from a list of other post types already created (and subsequently to link to them).

    For example, I am needing to create a post type called "Calendar" that will have a custom field called "Workshop." This field will list all the "Workshops" already created using another custom post type of the same name. The user will be able to easily assign what style of Workshop this Calendar entry is by selecting it off a dropdown, which will be generated dynamically from whatever "Workshops" have been created.

    Does this make sense? It seems like something that has been done before but I haven't the slightest clue on how to do it.
  • Well, took me around 4-5 hours but I figured this one out. Used Custom Field Template along with this custom wpdb query:

    <?php global $wpdb;
    $items = $wpdb->get_results(\"SELECT ID, post_title
    FROM $wpdb->posts
    where post_type = 'schedule'
    and post_status = 'publish'
    order by post_date DESC\");
    $i = 0;
    foreach ($items as $item) {
    $values[$i] = $permalink = get_permalink($item->ID);
    $valueLabel[$i] = $item->post_title;
    $i++;
    }
    ?>


    I can explain further if needed! :ugeek:
  • A very interesting case! Nice find on the solution.