dtczp02204 2016-04-03 00:34
浏览 30

ACF表格 - 如何使用多阵列添加_post_meta?

I have a question, hope it's not too much to ask for a beginner. It's basically a drop-down box letting you choose a car and submit your name to a list. I will add the remove functionality later, along with code sanitization.

What it is: It's a drop-down <select> form that lets you choose an <option>. I'm trying to get the form to submit the chosen <option> and the logged-in user's name to an array like so:

entries =>
     0 =>
string 'Mercedes SLS AMG GT3' (length=20) <- the <option> chosen
string 'John Doe' (length=20) <- the user's name
     1 =>
string 'Audi GT3' (length=20) <- the <option> chosen
string 'Peter Smith' (length=20) <- the user's name

etc...

I have an Advanced Custom Field setup (referenced from another node type), as the <select><option> list.

Pastebin if you don't want to read below: http://pastebin.com/Hd1kiHxm

!! Thank you so ever much to anyone that wishes to help a noob on a hobby project !!

CODE BELOW:

<!-- Series Cars Stuff -->
<?php

$posts = get_field('series_cars_reference');
if( $posts ): ?>
    <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
        <?php setup_postdata($post); ?>
            <form name="choose_car" method="POST" action="">   
            <?php
            $rows = get_field('cars');
            if($rows) {
                echo '<select name="cars">';
                foreach($rows as $row)
                {
                    echo '<option name="cars" value="' . $row['car'] . '">' . $row['car'] . '</option>';
                }
            echo '</select>';
            echo '<input type="submit" name="submit" value="Submit"/>';
            }
        $current_user = $current_user->display_name;            
        $selectOption = Array(
          'entry' => array(
            'name' => $current_user,
            'car' => $_POST['cars'],
        ));
echo '<pre>'; print_r($selectOption);echo '</pre>';
            if(isset($_POST['submit'])){
                add_post_meta( get_the_ID(), 'entries', $selectOption );
            }
            ?>
            </form>

<!-- SHOW ALL POST DATA - VAR DUMP PRINT -->   
<h3>All Post Meta</h3>
<?php $getPostCustom=get_post_custom(); // Get all the data ?>
<?php
    foreach($getPostCustom as $name=>$value) {
        echo "<strong>".$name."</strong>"."  =>  ";
        foreach($value as $nameAr=>$valueAr) {
                echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                echo $nameAr."  =>  ";
                echo var_dump($valueAr);
        }
        echo "<br /><br />";
    }
?>

// BELOW IS WHAT THE OUTPUT PRINT VAR STUFF LOOKS LIKE:

entries =>
     0 =>
string 'a:2:{s:4:"name";s:5:"admin";s:3:"car";s:20:"Mercedes SLS AMG GT3";}' (length=67)
     1 =>
string 'a:2:{s:4:"name";s:5:"admin";s:3:"car";s:20:"Mercedes SLS AMG GT3";}' (length=67)
     2 =>
string 'a:2:{s:4:"name";s:5:"admin";s:3:"car";s:20:"Mercedes SLS AMG GT3";}' (length=67)
     3 =>
string 'a:2:{s:4:"name";N;s:3:"car";s:20:"Mercedes SLS AMG GT3";}' (length=57)
     4 =>
string 'a:2:{s:4:"name";N;s:3:"car";s:20:"Mercedes SLS AMG GT3";}' (length=57)
     5 =>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值