0
worpressのデータベーステーブルクエリの値と同じ数のドロップダウンを作成する必要があります。私はforeachドロップダウンリストからUsermetaテーブルに投稿データを取得できません。これはコードです:SELECTのドロップダウンから可変値のPOSTデータを取得
$custom_posts_type = $wpdb->get_results("SELECT label,id FROM $table_name");
foreach ($custom_posts_type as $custom_post_type) {
$custom_post_type_name = $custom_post_type->label;
$custom_post_type_id = $custom_post_type->id;
?>
<p>
<label for="dropdown">Permisos de usuario para <?php echo $custom_post_type_name;?>: </label>
<?php
$user_custom_post = 'user_custom_' . $custom_post_type_name;
$selected = get_the_author_meta($user_custom_post, $user->ID);
$post_type_object = get_post_type_object($custom_post_type_name);
$label = $post_type_object->label;
$posts = get_posts(array('post_type'=> $custom_post_type_name, 'post_status'=> 'publish', 'suppress_filters' => false, 'posts_per_page'=>-1));
echo '<select name="' . $user_custom_post . '" id="' . $user_custom_post . '">';
?>
<option value="all" <?php selected($user_custom_post[0], "all"); ?>>All <?php echo $label;?></option>
<?php
foreach ($posts as $post) {
echo '<option value="', $post->ID, '"', $selected == $post->ID ? ' selected="selected"' : '', '>', $post->post_title, '</option>';
}?>
<?php
echo '</select>';
?>
</p>
<?php
update_user_meta($user->ID, $user_custom_post, $_POST[$user_custom_post]);
} //endforeach
ご協力いただきありがとうございます。 Thks
...
問題は変数を使用している可能性がある。しかし、このコードは動作しません
:そして、私はそれが動作変数を使用しない場合生成されたhtmlがどのようになっているか、$ _GET変数または$ _POST変数を(あなたのフォームで使用しているメソッド属性に応じて) "var_dump"した場合に得られるもの – flynorc
コメントflynorcのThks。 "通知:未定義インデックス:user_custom_xxxxxxx"とデータベース保存: "null" –
2つのファイル(1つのファイルに2つのコード)...メソッドとアクション属性を持つ