abrudtkuhl / WordPressSharp

A C# client to to interact with the WordPress XML-RPC API
abrudtkuhl.github.io/WordPressSharp/
GNU General Public License v3.0
103 stars 49 forks source link

How to Find Out if Published Post Already Exists ? #92

Open GlennIM opened 6 years ago

GlennIM commented 6 years ago

Before I publish a post I need to know if the post already exists. I know what the title of the post is but I need a way to search the blog for an existing post using the title I already know.

I tried calling the method GetPosts() as shown below but it throws an exception. What can I do to get a list of published posts so that I can search the list. If the list contains the post I need to get the post URL. In the code below, I changed PostStatus to "draft" and the code worked but only returned 10 draft posts and the blog has over 600.

var posts = client.GetPosts(new PostFilter { PostType = "post", PostStatus = "publish" }).OrderByDescending(a => a.Id).ToList();

I changed my code to pass null to the PostFilter as shown below but get the following unhandled exception.

var posts = client.GetPosts(null);

Both lines of code above return the same exception below...

CookComputing.XmlRpc.XmlRpcInvalidXmlRpcException

"response contains invalid dateTime value [response : array mapped to type Post[] : element 2 : struct mapped to type Post : member FeaturedImage mapped to type Object : struct mapped to XmlRpcStruct : member date_created_gmt : dateTime]"

Please Help! Thanks, Glenn

Blackcat156 commented 6 years ago

You can write a spider and search it directly on Web pages.