Я пытаюсь сохранить пользовательский тип записи.Я не могу понять, почему сохранение не работает для полей ввода, перечисленных ниже.
Я включил весь соответствующий код, так как не вижу, в чем проблема.Кажется, что все работает, кроме функции сохранения (перечислены в последнюю очередь).
Я пытаюсь сохранить входы только там, где 'type' => 'singleinput'
.Я не пытался сохранить 'fulltext'
единицы.
Кто-нибудь может указать, где я ошибаюсь?
//input boxes for custom post
$specialpage->inputs = array(
'item1' => array(
'type' => 'singleinput',
'headline' => 'Page headline',
'bullet1' => 'Bullet Point 1:',
'bullet2' => 'Bullet Point 2:',
'bullet3' => 'Bullet Point 3:'
),
'item2' => array(
'type' => 'fulltext',
'promo1' => 'Promo text 1:',
'promo2' => 'Promo text 2:',
'promo3' => 'Promo text 3:'
),
'item3' => array(
'type' => 'singleinput',
'quote' => 'The quote'
)
);
Эта функция вызывается для отображения мета-блока.
public function display_meta_box_($post_object){
foreach($this->inputs as $item){
foreach($item as $name => $title){
if ($title == 'singleinput'){
$activate = 'singleinput';
continue;
}
if ($title == 'fulltext'){
$activate = 'fulltext';
continue;
}
if ($activate == 'singleinput'){
$this->singleinput[$name] = $title;
${$this->name . $name} = get_post_meta($post_object->ID, $this->name . $name, true);
echo '<span class="meta_titles">' . $title . '</span>';
?>
<input type='text' class='input_single' name='<?php echo $this->name . $name;?>_name' value='<?php echo ${$this->name . $name}; ?>' >
<?php
}
}
Это функция сохранения
public function save_profile( $post_id, $post_object ) {
if( $this->name == $post_object->post_type){
//check if singleinput are defined for this custom post type
if ($this->singleinput){
//save single line text input boxes
foreach ($this->singleinput as $name => $title){
update_post_meta($post_id, $this->name . $name, $_POST[$this->name . $name . '_name']);
}
}
}
Редактировать: добавлена функция сохранения
$simplejoiner->saveNow();
public function saveNow(){
add_action( 'save_post', array($this, 'save_profile'), 10, 2 );
}