• Bunny

    (@mike268)


    I get the following error when using the ajax action wpex_titles:

    PHP Warning: Invalid argument supplied for foreach() in /website/wp-content/plugins/wp-experiments-free/wpex.class.php on line 247

    In the following piece of code, the casting of $_POST[‘id’] as int in the foreach causes the issue:

        public function ajax_titles()
        {
            $titles = array();
            $images = array();
            if (isset($_POST['id']))
            {
                $cur_page = isset($_POST['cur_id']) ? intval($_POST['cur_id']) : null;
                foreach ((int)$_POST['id'] as $id) {                                           // <====== this line is causing the issue
                    $images[$id] = array(
                        "old" => get_post_thumbnail_id($id)
                    );
                    $titles[$id] = $this->titles("", $id, true, $id == $cur_page);
                    // the titles() call will update a global variable which will
                    // effect the return result of get_post_thumbnail_id
                    $images[$id]["new"] = wp_get_attachment_url(get_post_thumbnail_id($id));
                }
                echo json_encode(array(
                    'images' => $images,
                    'titles' => $titles
                ));
                die();
            }
        }

    If you could fix it that would be awesome!

  • The topic ‘Issue in the AJAX action’ is closed to new replies.