I have 2 custom post types created with ACF
1 is check box, meta key = google_search
2nd is a text field, meta key = search_keyword
While publishing post I want to check if the google_search is checked and there is a value in search_keyword then
- Get the search_keyword value and save in to a custom table
- if search_keyword is empty then use the Title of post and save it into the custom table.
I tried this code in functions.php and post.php (both) but no luck,
add_action('save_post', 'googleSearch');
function googleSearch()
{
global $wpdb;
if ( $_POST['google_results'] == "Y") // if checkbox (google_search) is checked
{
if ($_POST['search_keyword'] != "") // if search_keyword has value
{
$sSearchKeyword = get_field('search_keyword');
}
else
{
//if search_keyword is empty then use post title as keyword.
$sSearchKeyword = get_the_title( );
}
$wpdb->query("INSERT INTO tbl_keyword SET post_id = '$post_ID',
keyword = '$sSearchKeyword'");
}
}
Any help how to get custom field values while saving post and save these values in db.