How to store a value on WP_option table

<?php
function myplugin_register_settings() {
       add_option('marker_pin','');
    register_setting( 'marker_group', 'marker_pin', 'myplugin_callback' );
}

add_action( 'admin_init', 'myplugin_register_settings' );

function myplugin_register_options_page() {
  add_options_page('Google Map', 'Map', 'manage_options', 'Google_map', 'myplugin_options_page');
}
add_action('admin_menu', 'myplugin_register_options_page');


function plugin_admin_enqueue_styles() {
       wp_enqueue_script( 'google-maps', 'https://maps.googleapis.com/maps/api/js?key=AIzaSyBPUcMLet39Rn_MXvOJErCbT7VnsOAVPWc&libraries=places&callback=initMap', array('jquery'),'1.0', true );
       wp_enqueue_script( 'ajax-js', 'https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js', array('jquery'),'1.0', true );
       wp_enqueue_script( 'code-js', 'https://code.jquery.com/jquery-1.11.3.min.js', array('jquery'),'1.0', true );
}
add_action( 'admin_enqueue_scripts', 'plugin_admin_enqueue_styles' );



function myplugin_options_page()
{

?>
  <div>
  <?php screen_icon(); ?>
  <h2>My Plugin Page Title</h2>
  <form method="post" action="options.php">
  <?php settings_fields( 'marker_group' ); ?>
  <h3>This is my option</h3>
  <p>Some text here.</p>
  <table>
  <tr valign="top">
  <th scope="row"><label for="marker">City:</label></th>
  <td>
    <?php  $pins = get_option('marker_pin'); ?>
    <div id="pac-container">
        <input id="pac_input" type="text" name="pac_input"
            placeholder="Enter City" value="<?php echo $pins; ?>">
    </div>

  </td>

  </tr>
  </table>
  <?php submit_button(); ?>

  <input type='button' value='Add Button' id='addButton'>
  </form>
  </div>

<?php

}
function update_option_fn()
{
   $name=$_POST['name_palce'];
   echo $name;
   update_option('marker_pin',$name);
}
add_action('wp_ajax_update_option_fn', 'update_option_fn');
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
 <script>
        function initMap() {

          var input = document.getElementById("pac_input"); 

          var autocomplete = new google.maps.places.Autocomplete(input);

          autocomplete.addListener('place_changed', function() {

          var place = autocomplete.getPlace();
          var placename = place.name;
          input.value=placename;

          if (!place.geometry) {
            alert("No details available for input: '" + place.name + "'");
            return;
          }

        });

      }

      $(document).ready(function() {
         /*$('#pac_input').on('input', function()*/
           $('#pac_input').focusout(function() {
                var Place =  $('#pac_input').val(); 
                console.log(Place);
                $.ajax({
               url: '<?php admin_url( 'admin-ajax.php' );?>',
               data: {"action":"update_option_fn","name_palce" :Place},
               /*data: {name_palce :Place},*/
               type: 'POST',
               success:function(data){
                   console.log("success"+data);
               }
              });
            });

            $("#submit").click(function() {
            <?php 
                $id = $_POST['name_palce'];
                update_option('marker_pin',$id,true);

            ?>
          });
        });



</script>

This my code, I want to store a value which come from ajax into wp_option table
how I can do it????

$299 Affordable Web Design WordPress

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

How to store a value on WP_option table

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.