Export posts manually selected by end user (not logged in)

For an intranet project, I’d like to have not logged in users be able to manually check posts (with checkbox in front of post title on archive page) and be able to export some predefined data about those posts (ex: title, date, author, acf field…) in a format (json, csv…)
I’m quite new to WordPress development, can someone points me to some direction or resources?
Thank you

1 Answer
1

I would recommend doing it mostly in Javascript:

Basic steps (pseudo code):

  1. On the archive page add check boxes <input type="checkbox" name="post-with-id-1" value="1"> next to each post and a submit button <input type="submit" value="Submit"> at the top or bottom of the page.
  2. In js, listen for clicks on the submit button. When it is clicked check which checkboxes are checked and create an array of post ids.
  3. The simplest thing to do then would be to build a url that opens a page in the browser from the REST API like this http://demo.wp-api.org/wp-json/wp/v2/posts?include[]=470&include[]=469 where you append an ‘include[]=470’ for each of the selected posts. That url will build JSON Array that includes object representations of each of your posts.

Leave a Comment