How to get all the posts from a wordpress blog using client.call function?

Question:

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?

Asked By: Naman Sogani

||

Answers:

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

Answered By: sgp

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
Answered By: Ahmed Soliman