wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
342 stars 130 forks source link

Post.query with "statuses" filter does not work #109

Closed Marneus77 closed 5 years ago

Marneus77 commented 6 years ago

When making a postquery with filter on status, an error comes: "invalid parameter: status" Querytext should be "statuses"

   /// <summary>
    /// Limit result set to posts assigned one or more statuses.
    /// </summary>
    /// <remarks>Default: publish</remarks>
    [QueryText("statuses")]
    public Status[] Statuses { get; set; }

It's probably the same in others utility.querybuilder classes.

More than that, once fixed, I seem to be still only getting the default "publish". This problem seems to be coming from Wordpress.com because entering the url manually with &statuses=draft,pending returns published posts too

ThomasPe commented 6 years ago

so this is a wordpress.com issue, not with self-hosted wordpress sites? The WordPress Rest API Docs have it as status.

polushinmk commented 6 years ago

@Marneus77 to query posts by statuses you must use authorization. So try to change your code like:

var result = await client.Posts.Query(postsquerybuilder,true);

UPD: in WP API this fields named status so in our library it naming correctly. When you changed status to statuses WP couldn`t find it and so just ignores it :)

Marneus77 commented 6 years ago

I checked a self-hosted WP site, it's the same: statuses

Thanks for the tip. But I then have to implement authentication? I don't have the jwt plugin installed on the blog, how do I authenticate?

polushinmk commented 6 years ago

Install JWT and configure it. Field name is status. You could check it in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php line 184 Statuses isn`t exist in WP REST API so it ignores it and returns default - publish posts.