Custom Fields
Re-Envisioned
Support MB Relationships Add meta data to field settings to identify as relationship field

This topic contains 5 replies, has 2 voices, and was last updated by  Clayton Collie 3 months ago.

  • Creator
    Topic
  • #11883
    Resolved
    Clayton Collie
    Participant

    I am rolling my own REST API endpoint using some of your code. I want to pick out certain sets of field to include in my endpoint. My main dilemma is that your rest api response shows values for the posts as ID and I need them as the post title. So I am looping through my group fields and also my relationship fields. In the group fields, there is a meta key value to call out the fact that is a group field. In your code you use in_array to accomplish this. Can you add the same meta key to a relationship field? It goes with the stuff like placeholder, name, id, field type, etc. Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #12044

    Clayton Collie
    Participant

    bump

    #12055

    Anh Tran
    Keymaster

    Hi Clayton,

    Sorry for the delay. Are you using MB Rest API or you’re going to write a custom endpoint?

    I’m not sure how you loop through fields. Can you give more details on that?

    #12082

    Clayton Collie
    Participant

    I am writing my own endpoint.

    But i don’t need help with the rest api. I need a field setting to be added to the Relationship field so I can distinguish it from other fields. I am using rwmb_get_object_fields to get all fields for an object then trying to single out the relationship fields with an in_array of some sorts. I can do this just fine for groups fields since there is a field setting type => group in that array. I would like something similar in the Relationship field. Just one little key value pair since the field_type key is already taken.

    #12121

    Anh Tran
    Keymaster

    I got it. Can you try differentiate the relationships fields by ID? Their IDs are always {$rel_id}_from or {$rel_id}_to.

    #12208

    Clayton Collie
    Participant

    After I found all object fields for a post object. I looped through each field and used this conditional to make sure I was grabbing a relationship field.

    if ( 'post' === $field['type'] && strpos( $field['id'], '_to' ) !== false && strpos( $field['id'], '_from' ) !== false )

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.