0

EDIT I changed it to

            if(isset($_POST['Make']))
    update_post_meta($pid,"Make", $_POST['Make']);

if(isset($_POST['Year']))
    update_post_meta($pid,"Year", $_POST['Year']);

if(isset($_POST['Model']))
    update_post_meta($pid,"Model", $_POST['Model']);

if(isset($_POST['Trim']))
    update_post_meta($pid,"Trim", $_POST['Trim']);

And now it is working intermittently

END EDIT

I am updating meta boxes I created. They function flawlessly on the back-end. But on the front end I am having limited success. Firebug says the POST request has the values in them but they are not ending up in the database.

Can anyone tell me why?

add_post_meta($pid, 'Year', $_POST['Year'], true);

is posting the meta key but not the meta value of a select box?

More information available if you need just let me know what it is.

EDIT TO PROVIDE MORE CODE This a condensed version of the form

    <form method="post" <?php echo $enc; ?>  action="<?php 
     echo post_new_with_pid_stuff_thg($pid,  
     $new_auction_step);?>" > 
     <ul class="post-new">
     <li>

    <?php do_action('cn_before_image_upload');

if(isset($_POST['Make']))
update_post_meta($pid, 'Make', $_POST['Make'], true);

if(isset($_POST['Year']))
            update_post_meta($pid, 'Year', $_POST['Year'], true);


if(isset($_POST['Model']))
    update_post_meta($pid, 'Model', $_POST['Model'], true);

if(isset($_POST['Trim']))
    update_post_meta($pid, 'Trim', $_POST['Trim'], true);
 ?>
  </li>

This is the before_image_upload in functions.php

        add_action('cn_before_image_upload', 'custom_nate_car');

       function custom_nate_car(){

      include_once 'select.php';
     global $wpdb;
     ?>
     <script type="text/javascript">
    $(document).ready(function(){
        $("select#Trim").attr("disabled","disabled");
        $("select#Model").attr("disabled","disabled");
        $("select#Make").attr("disabled","disabled");
        $("select#Year").change(function(){
        $("select#Make").attr("disabled","disabled");
        $("select#Make").html("<option>wait...</option>");
        var id = $("select#Year option:selected").attr('value');
        $.post("<?php bloginfo('template_url');?>/select_type.php", {id:id},  
        function(data){
            $("select#Make").removeAttr("disabled");
            $("select#Make").html(data);

        });
        });
       $('select#Make').change(function() {
       $("select#Model").attr("disabled","disabled");
        $("select#Model").html("<option>wait...</option>");
        var id2 = $("select#Make option:selected").attr('value');
        $.post("<?php bloginfo('template_url');?>/select_model.php", {id2:id2}, 
        function(data2){
            $("select#Model").removeAttr("disabled");
            $("select#Model").html(data2);
       });

        $('select#Model').change(function() {
       $("select#Trim").attr("disabled","disabled");
        $("select#Trim").html("<option>wait...</option>");
        var id3 = $("select#Model option:selected").attr('value');
        $.post("<?php bloginfo('template_url');?>/select_trim.php", {id3:id3}, 
        function(data3){
            $("select#Trim").removeAttr("disabled");
            $("select#Trim").html(data3);
       });
       $("form#select_form").submit(function(){
        var year = $("select#Year option:selected").attr('value');
        var make = $("select#Make option:selected").attr('value');
        if(year>0 && make>0)
        {
            var result = $("select#Make option:selected").html();
            $("#result").html('your choice: '+result);
        }
        else
        {
            $("#result").html("you must choose two options!");
        }
        return false;
    });

});
       });
      });
     </script>

    <h2>Car YEAR/MAKE/MODEL/TRIM:</h2><br />
    <select name="Year" class="do_input" size="20" id="Year">
        <?php echo $opt->getYear(); ?>
    </select>
    <select name="Make" class="do_input" size="20"  id="Make">
      <option>Choose...</option>
    </select>
    <select name="Model" class="do_input" size="20" id="Model">

    </select>
    <select name="Trim" class="do_input" size="20" id="Trim">

    </select>
    <br /><br />

the select.php that the jquery calls is formatted like this

class selectList {

public function getModel(){
    global $wpdb;
    $sql = $wpdb->get_results(
        "

        SELECT DISTINCT model, make

        FROM wp_car_details 

        WHERE make = '$_POST[id2]'

        ORDER BY model ASC

        "
        );

    foreach ($sql as $res) {
    echo '<option value="'.$res->model.'">'.$res->model.'</option>';
    }
    die();
}

one public function for each of the select boxes. is there a problem with my loop?

EDIT Did var_dump($_POST);

Looks like the select values are not going in into the $_POST array but showing fine in firebug.

  • Can you add more code? Also I think that you'll use update_post_meta in place of add_post_meta. See the Codex for better knowledge. – Chinmoy Kumar Paul Aug 9 '14 at 3:17
  • Please don't post the same question twice. If you need to add more info, do it as an edit in your original post. Thank you – Pieter Goosen Aug 9 '14 at 4:29
  • This is an exact duplicate (double post) of Custom Meta Boxes Not Updating From Front End – Pieter Goosen Aug 9 '14 at 4:31
  • Sorry for the duplicate.. It didn't feel like I was doing that when I posted this... Problem corrected – Nathan Aug 9 '14 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.