Memo 1
Details for Memo 1
add_action('wp_ajax_add_memo', 'add_memo_callback');
add_action('wp_ajax_nopriv_add_memo', 'add_memo_callback');
function add_memo_callback() {
$title = sanitize_text_field($_POST['title']);
$details = sanitize_text_field($_POST['details']);
global $wpdb;
$wpdb->insert('my_memos', array(
'title' => $title,
'details' => $details,
));
$memoList = get_memo_list();
wp_send_json_success(array('memoList' => $memoList));
}
function get_memo_list() {
global $wpdb;
$memos = $wpdb->get_results('SELECT * FROM my_memos ORDER BY id DESC');
$output = '
- ';
foreach ($memos as $memo) {
$output .= '
- ' . esc_html($memo->title) . ': ' . esc_html($memo->details) . ' '; } $output .= '