Skip to content

Instantly share code, notes, and snippets.

@ilovefreesw
Forked from Suleman-Elahi/wptags.py
Created March 23, 2021 07:03
Show Gist options
  • Save ilovefreesw/8546150b84114da80b6a6cbd218ab17c to your computer and use it in GitHub Desktop.
Save ilovefreesw/8546150b84114da80b6a6cbd218ab17c to your computer and use it in GitHub Desktop.
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())
@ilovefreesw
Copy link
Author

Make sure to run pip install requests tqdm before running the script.

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