Viewing 0 reply threads
  • Author
    Posts
    • #7329
      dealerconsulting
      Participant

      Dear all!

      I’m glad to use piklist plugin and very apprieciative for your job.
      I’ve encountered the problem after upgrading to v.0.9.9.9 .
      Please look at the code below.
      11th line indicates an error

      Invalid argument supplied for foreach()

      .

      foreach ($fields[$key][‘request_value’] as $id)

      add_action( 'piklist_save_field', 'my_save_post', 10, 2 );
      
      function my_save_post($scope, $fields) {
              global $wpdb;
              if ($scope == 'relate-reverse')
              {
                      foreach ($fields as $key => $value)
                      {
                              if (substr_compare($key, '_relate_id', -strlen('_relate_id'), strlen('_relate_id')) === 0)
                              {
                                      foreach ($fields[$key]['request_value'] as $id)
                                      {
                                              foreach ($fields as $key => $value)
                                              {
                                                      if (substr_compare($key, '_post_id', -strlen('_post_id'), strlen('_post_id')) === 0)
                                                      {
                                                              foreach ($fields[$key]['request_value'] as $post_ids)
                                                              {
                                                                      foreach ($post_ids as $post_id)
                                                                      {
                                                                                      PikList_Form::relate($post_id, array($id));
                                                                      }
                                                              }
                                                      }
      
                                                      if (substr_compare($key, '_relate_remove', -strlen('_relate_remove'), strlen('_relate_remove')) === 0)
                                                      {
                                                              $remove = array_filter(explode(',', $fields[$key]['request_value'][0]));
                                                              foreach ($remove as $has)
                                                              {
                                                                      if ($found = $wpdb->get_var($wpdb->prepare("SELECT relate_id FROM {$wpdb->prefix}post_relationships WHERE post_id = %d AND has_post_id = %d", $has, $id)))
                                                                      {
                                                                              $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}post_relationships WHERE relate_id = %d", $found));
                                                                      }
                                                              }
                                                      }
                                              }
                                      }
                              }
                      }
              }
      }

      Thank you for your support.

      Regards,
      Arek

Viewing 0 reply threads
  • You must be logged in to reply to this topic.