Home › Forums › Backend Issues (wp-admin) › Update Checkbox Field with Multiple Values using MySQL Queries › Reply To: Update Checkbox Field with Multiple Values using MySQL Queries
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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.