Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get All WordPress Tags in Excel (CSV) using WordPress WP API v2
import requests
import csv
import time
from tqdm import tqdm
tags = {}
pages = int(requests.get('https://www.example.com/wp-json/wp/v2/tags').headers['X-WP-TotalPages'])
for i in tqdm(range(pages), ncols=65):
js = requests.get('https://www.example.com/wp-json/wp/v2/tags?page='+str(i+1)).json()
for entry in js:
tags[entry['name']]=entry['slug']
time.sleep(1)
with open("tags.csv", "w", newline='') as f:
datawriter = csv.writer(f)
datawriter.writerows(tags.items())
@Suleman-Elahi
Copy link
Author

Works like a charm:

image

Can also be used to get Posts (title, URLs) after a little tweaking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment