title: insert data in WordPress database as non-logged in user
body: <p>I created a custom post type called 'visitor'. and I have an input in the front end. when the user saves input, I want to grab that data and post it as 'title' in my 'visitor' post type.</p>
  
  <p>in functions.php-</p>
  
  <pre><code>$secureInfo= array(
    'site_url' =&gt; get_site_url(),
    'nonce' =&gt; wp_create_nonce("wp_rest")
  );
  
  wp_localize_script( "main-js", "data", $secureInfo);
  </code></pre>
  
  <p>in main.js-</p>
  
  <pre><code>sendUserInfo(){
      var grabbingInfo = {
        "title" : this.alertBoxInput.val() //my targeted input
      }
  
      $.ajax({
        beforeSend: (xhr) =&gt; {
          xhr.setRequestHeader("X-WP-Nonce", data.nonce);
        },
        url: data.site_url + "/wp-json/wp/v2/visitor", //custom post type
        data: grabbingInfo,
        type: "POST",
        success: (res) =&gt; {
          console.log("success");
          console.log(res);
        },
        error: (res) =&gt; {
          console.log("sorry");
          console.log(res);
        }
      });
  }
  </code></pre>
  
  <p>however, this code works for logged in user and says unauthorized for public users. but I don't care if a user is logged in or not. any suggestion?</p>