Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CustomFields property added to Post class #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cihant
Copy link

@cihant cihant commented Feb 8, 2018

@ThomasPe
Copy link
Member

ThomasPe commented Feb 8, 2018

hey, thanks for the PR! could you please

  • add some tests
  • add some documentation on how to use this (including your php script) to the Wiki
  • create an issue so I can link this PR to the next milestone

thanks!

@ghost
Copy link

ghost commented Feb 27, 2018

Hey many thanks for the code. Could you please tell me how to create new custom fields using your code? I am able to retrieve existing fields, however I had to modify post.cs : IDictionary<string,string>, string[] gave me a json deserializer error. Thanks in advance

@hbcondo hbcondo mentioned this pull request Jun 12, 2018
@ghost
Copy link

ghost commented Jun 26, 2019

If that can help, I was able to create / update customs fields by adding this to functions.php :

function custom_field_get_post_meta_cb($object, $field_name, $request){
			// return get_post_custom();

		$metas = get_post_custom($post_id);

		foreach($metas as $key => $value) {
			if(sizeof($value) == 1) {
			  $metas[$key] = $value[0];
			}
		}
		return $metas;			
}

function custom_field_update_post_meta_cb($value, $object, $field_name) {
    $postId = $object->ID;
	
    foreach ($value as $key => $Data) {
       update_post_meta($postId, $key , $Data);
    }
}
    add_action('rest_api_init', function(){
      register_rest_field('post', 'custom_fields', array(
	  'get_callback' => 'custom_field_get_post_meta_cb',
	  'update_callback' => 'custom_field_update_post_meta_cb',
      'schema'          => null,) ); 
});

@adelhoss
Copy link

in this link I Need Help you :
#190

@TheGameVlog
Copy link

Was this ever added to the main repo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants