开发者

How to insert content from another Custom Post type into Post?

Say I have a custom post type called "Performers". This gets filled with different bands/performers with a featured image as well as custom fields (mp3 file, facebook link, myspace link, etc).

I have another custom post type called "Events".

When I create a new Event, I would like the option to have a drop box to select one of t开发者_运维百科he bands from the "Performers" custom post type.

This will insert all data from the specific Band/Performer into the Event post (custom fields, featured image, etc.).

What is the best method to approach this?


a little bit of jQuery

jQuery("#dropdown").change(function() {
    jQuery.getJSON(
        ajaxurl,
        {action: "get_band_info", band: jQuery("#dropdown").val()},
        function(data) {
           jQuery("#facebook").val(data.facebook);
        }
    );
}):

and a little bit of php

add_action('wp_ajax_get_band_info', 'my_get_band_info');

function my_get_band_info() {
    echo json_encode(array(
        'facebook' => get_post_meta($_POST['band'], 'facebook', 'true')
    ));
    exit();
}

Should do the trick.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜