• Is there any way to dynamically register metadata for a user via the REST API?

    This is my use case:

    I have a multi-part Ninja form with one question on each part. Each time a user answers a question and saves, I’d like the user’s metadata to be updated via JavaScript with ‘question_0_answered’: ‘yes’.

    However, there’s no telling how many questions the client will end up coming up with so I’d rather not have to register them manually.

    Is there any way to dynamically create user meta via the REST API?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    There’s no way through the default routes, since meta values must be registered in order for them to be returned. You could register a single meta value and store a variable length array of various values though.

    If you must have separate meta values, you could create a custom API route and endpoints to manage this, you can then pretty much accomplish whatever you need. It’s difficult to query for objects based on a single value within an array of values. If that is a need, this is your best option. Otherwise, I’d just save an array in a single value.
    https://developer.wordpress.org/rest-api/extending-the-rest-api/routes-and-endpoints/

Viewing 1 replies (of 1 total)
  • The topic ‘Dynamically add user meta with REST API’ is closed to new replies.