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

Updating metas doesn't work #84

Closed vladopandzic closed 1 year ago

vladopandzic commented 6 years ago

I tried udpating yoast meta description field which is called "_yoast_wpseo_metadesc". However, when I try to update nothing changes. var metaDescYoast =new { _yoast_wpseo_metadesc = finalWord }; wordpressPost.Meta = new List { metaDescYoast }; var result = client.Posts.Update(wordpressPost).Result;

ThomasPe commented 6 years ago

you'll have to await the call, like this: var result = await client.Posts.Update(wordpressPost);

does this work?

rick-strand commented 6 years ago

@ThomasPe

I've tried the code above but it doesn't appear to work. It doesn't return an error but the meta title isn't updated in WP and isn't shown on the site.

var metaSample = new { title = "test" }; postSample.Meta = new List() { metaSample };

var result = await client.Posts.Update(postSample);

Any advice would be appreciated.

And thanks for creating this library!

ThomasPe commented 6 years ago

I this still an issue? Sorry for the late reply...

jasenf commented 4 years ago

Has anyone come up with the proper way to update the yoast meta description? I have tried every combination or keyword I can think of. A working example would be truly appreciated.

TylerByte666 commented 4 years ago

Can anybody confirm they have logged in using the jwt-auth before they tried?

Creating something like this would require elevated privileges on WordPress.

var client = new WordPressClient(ApiCredentials.WordPressUri);
client.AuthMethod = AuthMethod.JWT;
await client.RequestJWToken(ApiCredentials.Username,ApiCredentials.Password);

// check if authentication has been successful
var isValidToken = await client.IsValidJWToken();

if( isValidToken){
  var metaDescYoast =new { _yoast_wpseo_metadesc = finalWord };
  wordpressPost.Meta = new List
  {
    metaDescYoast
  };
  var result = await client.Posts.Update(wordpressPost);
}
jasenf commented 4 years ago

I am able to log in successfully, retrieve posts, create a new post. No problem. Just can't get the Yoast properties to stick.

However, I will say this reference to Meta = new List { metaDescYoast } does not even seem to be valid C#, you need some kind of type parameter. I'm doing new List to make that work.

TylerByte666 commented 4 years ago

I am able to log in successfully, retrieve posts, create a new post. No problem. Just can't get the Yoast properties to stick.

However, I will say this reference to Meta = new List { metaDescYoast } does not even seem to be valid C#, you need some kind of type parameter. I'm doing new List to make that work.

Yup, the code example was based off the above. Was just asking more about the auth part.

navjot50 commented 4 years ago

Do you have the show_in_rest = true for meta properties of Wordpress Post?

GiampaoloGabba commented 3 years ago

Hello i resolved with this plugin: https://it.wordpress.org/plugins/rest-api-meta-support/

Just install and enable it in wordpress, then you can store meta title and description in yoast using the Meta field

            Meta = new Dictionary<string, string>
            {
                {"yoast_wpseo_title", "your meta title"},
                {"yoast_wpseo_metadesc", "your meta description"},
            }