Support

Account

Forum Replies Created

  • None that I can see! The form seems to submit, the page redirects, but the field value is null:

    
    if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "new_post" ) { 
      // Do some minor form validation to make sure there is content
      if (isset ($_POST['title'])) {
          $title =  $_POST['title'];
      } else {
          echo 'Please enter a  title';
      }
      if (isset ($_POST['description'])) {
          $description = $_POST['description'];
      } else {
          echo 'Please enter the content';
      }
      
      $trendline_20 = serialize(array($_POST['trendline_20-m5bull'], $_POST['trendline_20-m5bear'], $_POST['trendline_20-m15bull'], $_POST['trendline_20-m15bear'], $_POST['trendline_20-m30bull'], $_POST['trendline_20-m30bear'], $_POST['trendline_20-h1bull'], $_POST['trendline_20-h1bear'], $_POST['trendline_20-h2bull'], $_POST['trendline_20-h2bear'], $_POST['trendline_20-h4bull'], $_POST['trendline_20-h4bear'], $_POST['trendline_20-d1bull'], $_POST['trendline_20-d1bear']));
      $option_liquidity = $_POST['option_liquidity'];
      $option_liquidity_min = $_POST['option_liquidity_min'];
      $option_liquidity_max = $_POST['option_liquidity_max'];
       
      // Add the content of the form to $post as an array
      $new_post = array(
          'post_title'    => $title,
          'post_content'  => $description,
          'post_status'   => 'draft',           // Choose: publish, preview, future, draft, etc.
          'post_type' => 'custom_scan'  //'post',page' or use a custom post type if you want to
      );
      //save the new post
      $post_id = wp_insert_post($new_post);
    
      global $wpdb;
    
      $wpdb->query(
        "INSERT INTO wp_postmeta (post_id, meta_key, meta_value) 
          VALUES ($post_id, 'trendline_20', $trendline20),($post_id, '_trendline_20', 'field_634819cc60fd8')"
      );
    
      //redirect
      wp_redirect(get_permalink($post_id)); exit;
    } ?>
    
  • Hi there! Thanks for your help with this.

    The below code works correctly:

    
    $trendline_20 = array($_POST['trendline_20-m5bull'], $_POST['trendline_20-m5bear'], $_POST['trendline_20-m15bull'], $_POST['trendline_20-m15bear'], $_POST['trendline_20-m30bull'], $_POST['trendline_20-m30bear'], $_POST['trendline_20-h1bull'], $_POST['trendline_20-h1bear'], $_POST['trendline_20-h2bull'], $_POST['trendline_20-h2bear'], $_POST['trendline_20-h4bull'], $_POST['trendline_20-h4bear'], $_POST['trendline_20-d1bull'], $_POST['trendline_20-d1bear']);
    
    update_field('trendline_20', $trendline_20, $post_id);
    

    However, when attempting to serialize and use $wpdb, the following does not work:

    
    $trendline_20 = serialize(array($_POST['trendline_20-m5bull'], $_POST['trendline_20-m5bear'], $_POST['trendline_20-m15bull'], $_POST['trendline_20-m15bear'], $_POST['trendline_20-m30bull'], $_POST['trendline_20-m30bear'], $_POST['trendline_20-h1bull'], $_POST['trendline_20-h1bear'], $_POST['trendline_20-h2bull'], $_POST['trendline_20-h2bear'], $_POST['trendline_20-h4bull'], $_POST['trendline_20-h4bear'], $_POST['trendline_20-d1bull'], $_POST['trendline_20-d1bear']));
    
    global $wpdb;
    
    $wpdb->query(
        "INSERT INTO wp_postmeta (post_id, meta_key, meta_value) 
          VALUES ($post_id, 'trendline_20', $trendline20),($post_id, '_trendline_20', 'field_634819cc60fd8')"
      );
    

    Why is $_POST working with update field() and not with $wpdb?

    Thanks again for your time and assistance.

Viewing 2 posts - 1 through 2 (of 2 total)