Support

Account

Home Forums Add-ons Options Page Option repeater field and custom post type

Solving

Option repeater field and custom post type

  • Hello Everybody,
    I’m owner of ACF Pro and I’m looking to display on a custom post type one or further fields from an option page.
    Let me explain, I hop it will be clear 😉
    I created first a custom post type. To this custom post type I create an option field.
    In this option field I have :
    -Group
    –Repeater field
    —Title
    —Description
    —Link
    -Text Field

    I reached to populate the repeater field title to my custom post type as a radio button field.

    Now I would like to display the description field using the ID of my radio button populate field.

    Any help is really appreciated, I’ve been stuck for two days with this.

    Best.

    Pierre

  • Maybe, I’m doing wrong with a populated radio button field.
    What do you think of this solution ?
    https://www.advancedcustomfields.com/resources/bidirectional-relationships/
    Best

  • Hi again,
    I’m looking to my database and I don’t understand how to find a link by post_id, meta_id and option_id
    Any help appreciated.
    All the best.

  • Sorry, but I don’t understand your explanation of what you are trying to do. Please try to explain more clearly and in more detail and maybe someone will be able help you.

  • Hello @John,
    many thanks for your answer.
    I’m sorry, I didn’t explain well how I did and what are my goals.

    Here is a diagram of what I did.
    CTP and Options IMG

    The idea is to make relationship between custom posts and their own options fields.
    For example with three custom posts which display their own informations/values from options fields.

    CTP 1 -> repeater “Subject” row[1] -> Title, description, textfield, etc. and from the other repeater field “Location/Town” row[4].

    CTP 2 -> repeater “Subject” row[4] -> Title, description, textfield, etc. and from the other repeater field “Location/Town” row[1].

    CTP 3 -> repeater “Subject” row[2] -> Title, description, textfield, etc. and from the other repeater field “Location/Town” row[2].

    I delete Group field which was unecessary.
    I populate title and town from options to my custom post two dedicated radio fields.

    Now I’m looking for displaying on the frontend values from options fields that “belong to my custon post”.
    Populate not do relationship between CPT and Options.
    I tought that with post_id, I’ll be able to display options values like I can do with taxonomies.
    Am I wrong ?

    I hope it’s more clear…

    Let me know.

    All the best.

    Pierre

  • Are you using relationship fields for these.

    
    // get the relationship field
    $posts = get_field('relationship_field_name');
    // then loop over the relationship and get values from the related posts
    foreach ($posts as $post) {
      $some_value = get_field('field_on_related_post', $post->ID);
    }
    

    Let me know if I’m misunderstanding what field type you are using here.

  • No, I didn’t use relationship field at all.
    But maybe I should.
    Best

  • I cannot create a relation ship from custom post to options.
    A custom post must be linked to only one subject and one location.
    A subject and a location can be linked to many posts.
    Best

  • Hi @john,
    I’m reaching what I want to do but with custom taxonomies.
    It would be awesome to do the same thing with options, it’s user friendly with options.
    I will try to reach with options a bit later for the challenge ;-).
    Have a nice day.
    Best

  • So your relationship is selecting a row from a repeater that is on an options page? How are you uniquely identifying each row?

  • That’s where I’m blocked.
    I’m not able to identifying each row using Title populate field for exemple.

  • There isn’t any way in ACF to identify rows of a repeater. Rows can be moved so the index is not suitable. You would have to build your own mechanism for identifying them. For example you could add another field to each row and dynamically populate the value of this row with some unique value that will never change.

    There have been many topics here about doing the above, here is one example https://support.advancedcustomfields.com/forums/topic/unique-id-for-repeater-field/

    https://github.com/philipnewcomer/ACF-Unique-ID-Field

    What you are trying to do would be better suited to using a custom post type than an repeater on an options page.

  • Thanks for your answer.
    My populate field has a unique ID but not linked to the row.
    I’ll dig with the links you gave me.

    Yes, you’re probably right that it would be better using another custom post type and doing relashionship between us.
    I’ll try it too.

    Many thanks for your time.

    All the best.

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.