Reputation: 949
I am using python wordpress_xmlrpc library for extracting wordpress blog data. I want to fetch all posts of my wordpress blog. This is my code
client = Client(url, 'user', 'passw')
all_posts = client.call(GetPosts())
But this is returning only the latest 10 posts. Is there any way to get all the posts?
Upvotes: 1
Views: 2864
Reputation: 1710
This is how I do it :
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts
from wordpress_xmlrpc import WordPressTerm
from wordpress_xmlrpc.methods import posts
client = Client('site/xmlrpc.php', 'user', 'pass')
data = []
offset = 0
increment = 20
while True:
wp_posts = client.call(posts.GetPosts({'number': increment, 'offset': offset}))
if len(wp_posts) == 0:
break # no more posts returned
for post in wp_posts:
print(post.title)
data.append(post.title)
offset = offset + increment
Upvotes: 2
Reputation: 1768
According to the documentation, you can pass a parameter indicating how many posts you want to retrieve as:
client.call(GetPosts({'number': 100}))
Alternatively, if you want to get all the posts, check this out: https://python-wordpress-xmlrpc.readthedocs.org/en/latest/examples/posts.html#result-paging
Upvotes: 0