на этот раз я бы добавил wordpress meta_box, вызвав wp_ajax.Wordpress Meta box с ajax
Я пробовал это, но не работает.
add_action('add_meta_boxes', 'add_custom_meta_box', 'post_type');
function add_custom_meta_box($post_type) {
if ($post_type == 'minisites') {
add_meta_box('sections_meta_box', 'Add Section', 'show_custom_meta_box');
// echo Utils::createStructureBox();
}
if ($post_type == 'sections') {
add_meta_box('sections_structure_box', 'Section Structure', 'show_section_structure_box');
}
}
function show_custom_meta_box() {
echo Utils::createSelect();
echo Utils::includeScripts();
}
function show_section_structure_box() {
echo "Done";
}
add_action('wp_ajax_addStructureBox', 'addStructureBox');
function addStructureBox() {
add_custom_meta_box('sections');
}
и JQuery
$(document).ready(function() {
$('.addSection').on('click', function() {
var selectedSection = $('#sections option:selected').text();
$.post(ajaxurl, {action: 'addStructureBox', section: selectedSection}, function (data) {
alert(data);
});
});
});
, кажется, хорошо, но называют add_custom_meta_box в addStructureBox не работает, по-видимому.
Значит, любые идеи?
Заранее спасибо
Джузеппе
Edit: HTML код
public static function createSelect() {
$sections = get_posts(array(
'post_type' => 'sections')
);
$html = '<select id="sections" name="item[]">';
foreach ($sections as $section) {
$html .= '<option value="' . $section->ID . '">' . $section->post_title . '</option>';
}
$html .= '</select><br><br>';
$html .= '<input type="button" class="button button-primary button-large addSection" id="add" value="Add"></button>';
return $html;
}
Edit: Скриншот
Почему вы хотите обмен веществ через ajax? – madalinivascu
Мне нужно добавить мета-ящик, когда я нажимаю кнопку добавления раздела из первого мета-поля –
, почему бы не загружать мета-окно? – madalinivascu