Last active
December 28, 2020 16:51
-
-
Save riyadhalnur/110063fe58784643db90 to your computer and use it in GitHub Desktop.
Script to run queries against a WordPress site using Python. Install the library using `pip install python-wordpress-xmlrpc` before running this script. Run this script in the terminal using `python wp.py`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from wordpress_xmlrpc import Client, WordPressPost | |
from wordpress_xmlrpc.methods.posts import GetPosts, GetPost | |
wp = Client('https://yoursiteaddress.com/xmlrpc.php', 'username', 'password') # update the site address, username and password | |
# retrives the list of all posts in the blog. Optional: you can supply filters and fields to sort by. | |
print(wp.call(GetPosts({'post_status': 'publish'}))) | |
# retrives a single post in the blog. Required: postId. Optional: fields | |
# pass in postId when running this script, e.g python wp.py 1234 | |
postId = sys.argv[1] # needs to be a valid post ID | |
print(wp.call(GetPost(postId))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment