I would like to retrieve the content of posts from my WordPress blog. Using the package RWordPress
it is straightforward to retrieve categories and tags and titles, but what about the content of posts?
# Download and load the package
if (!require('RWordPress')) {
devtools::install_github(c("duncantl/XMLRPC", "duncantl/RWordPress"))
}
library(RWordPress)
# list all the functions in the package
lsf.str("package:RWordPress")
Here, for example, is the code to obtain categories, with my specifics redacted in brackets:
Cat <- getCategoryList(login = c([my user name] = '[my password'),
.server = 'http://[my blog on].wpengine.com/xmlrpc.php')
The linked SO question is not applicable as it doesn't use RWordPress [HTML and CSS and PHP coding].
This site is about posting on WordPress, not retrieving from WordPress [publishing, not gettting]. Another question uses xmlrpc as does RWordPress and a getPosts call, but it does not rely on R.
Posts <- getPosts(num = 100, blogid = 0L, login = c([my user name] = '[my password]'), .server = 'http://[my blog name].wpengine.com/xmlrpc.php')
The above code returns dates and titles and status, but not content.
Thank you for any guidance.
******************* Edit after first answer
After requiring RWordPress
and XMLRPC
, and then defining an object for login and for the .server, here is the console message:
> getPageList(blogid = 0L, login = WordpressLogin, .server = WordpressURL)
Error in xml.rpc(.server, op, as.integer(blogid), names(login), as.character(login), :
Problems
I find that "Problems" is not an informative error message for me.
Log into your WordPress admin panel and go to Pages or Posts (Depending on which one you want to restore). Click on Trash and you'll be redirected to all your deleted pages and posts. Select the page you want to restore, and two options will appear under it – Restore and Delete Permanently.
To restore a blog: Sign in to Blogger. At the top left, under "Trashed blogs," click the blog you want to restore. Undelete.
If the post was created on the dashboard of your own blog at Dashboard > Posts > All Posts > Add New then you ought to be able to recover a lost post or page from revisions if needs be. If you cannot locate a revision or restore from Trash then the content has been lost and cannot be recovered.
In your WordPress admin dashboard, go to Pages > All Pages. Look for the Trash tab storing all the pages that have been deleted during the last 30 days. Hover your mouse over the deleted page you'd like to recover. Click “Restore.”
Tell me if I am missing something, but for me the description
identifier of posts seem to deliver the whole text.
RWordpress maps all the functions in XML-RPC wp
if (!require('RWordPress')) {
devtools::install_github(c("duncantl/XMLRPC", "duncantl/RWordPress"))
}
library(RWordPress)
options(WordpressLogin = c(myusername = 'mypassword'),
WordpressURL = 'http://localhost/myblog/wordpress/xmlrpc.php')
# library(knitr)
# can refer this page
# http://codex.wordpress.org/XML-RPC_wp
#Rwordpress has a one to one mapping
getCategories()
#get a list of pages
getPageList()
# pick one id from above list
id=27
getPage(pageid = id)
# description seems to have all the text of post, even though the
# document is sparse
getPage(pageid = id)$description
#similarly for posts
getPost(postid = 6)$description
I am of course using a locally installed blog, but I'd reckon this should work remotely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With