POST to WordPress database as anonymous user from front end for email capture.

[ad_1]

Hey there,

I have a form in the footer of my website for users to submit their email address to join our mailing list. My initial thought was to create a custom post type of email\_capture and using the rest api to make a post request at BASEURL + “/wp-json/wp/v2/email\_capture/”. I am receiving a 401 “Sorry, you are not allowed to create posts as this user.”

Is it possible to create a custom post type or a custom endpoint that allows anonymous posting but restricts read capabilities to administrators? Or should I take a completely different approach.

Similar stack overflow question [here](https://stackoverflow.com/questions/70980067/wordpress-rest-api-posting-data-from-a-form-as-a-guest-user) although no working response.

Thanks in advance.

[ad_2]
3 Comments
  1. Why are you trying to capture emails this way? You’re doing it wrong. Either integrate something like hubspot or use gravity forms or other solid plugin to store the data of submissions.

  2. You can use Javascript fetch api and make post request to custom function. save emails in wp_options or any custom table instead of CPT.

    But there are better ways to manage email lists.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer