Support

Account

Home Forums Add-ons Repeater Field Pulling in single data

Solved

Pulling in single data

  • Hey all.

    I’ll try to explain best I can as to what I am trying to do.

    So, I have set up an options page called ‘Presenters’ – Sat inside is a repeater field that allows you to add Image, Presenter name and a Bio. I want to have it so when somebody clicks on the DJ name, it will lead them to another page, and that DJ’s info will show, pulling from the repeater field.

    Right now, obviously, it’s pulling all the repeater data in, as it would. How do I target just the one entry, dependent on which DJ is clicked? – If this makes some sense?

    Thanks

  • Hi @antsykes95

    Could you please share the JSON export file of your field group so I can see your current setup?

    The easiest way to get the other data for a certain row is by checking the data inside it like this:

    // this data is retrieved dynamically
    $current_dj = "current dj name";
    
    $repeater_value = get_field('repeater_field_name', 85);
    
    foreach( $repeater_value as $row ){
        if( $row['presenter_name_field'] == $current_dj ){
            echo $row['bio_name_field'];
            echo $row['image_name_field'];
        }
    }

    I hope this makes sense 🙂

  • I would have done this myself in Custom Post Types but for some reason, the developer built this in Repeater fields and I have no time to re-build it. If push comes to shove, and the only way is in CPT, so be it.

    Here is said JSON file:
    [
    {
    “key”: “group_5829bc002480c”,
    “title”: “Presenters”,
    “fields”: [
    {
    “key”: “field_582a1ae64433e”,
    “label”: “Presenter List”,
    “name”: “presenter_list”,
    “type”: “repeater”,
    “instructions”: “”,
    “required”: 0,
    “conditional_logic”: 0,
    “wrapper”: {
    “width”: “”,
    “class”: “”,
    “id”: “”
    },
    “collapsed”: “”,
    “min”: “”,
    “max”: “”,
    “layout”: “table”,
    “button_label”: “Add Presenter”,
    “sub_fields”: [
    {
    “key”: “field_582a1c288dfe6”,
    “label”: “Presenter Image”,
    “name”: “presenter_image”,
    “type”: “image”,
    “instructions”: “”,
    “required”: 0,
    “conditional_logic”: 0,
    “wrapper”: {
    “width”: “”,
    “class”: “”,
    “id”: “”
    },
    “return_format”: “array”,
    “preview_size”: “medium”,
    “library”: “all”,
    “min_width”: “”,
    “min_height”: “”,
    “min_size”: “”,
    “max_width”: “”,
    “max_height”: “”,
    “max_size”: “”,
    “mime_types”: “”
    },
    {
    “key”: “field_582a1c3b8dfe7”,
    “label”: “Presenter Name”,
    “name”: “presenter_name”,
    “type”: “text”,
    “instructions”: “”,
    “required”: 0,
    “conditional_logic”: 0,
    “wrapper”: {
    “width”: “”,
    “class”: “”,
    “id”: “”
    },
    “default_value”: “”,
    “placeholder”: “”,
    “prepend”: “”,
    “append”: “”,
    “maxlength”: “”,
    “readonly”: 0,
    “disabled”: 0
    },
    {
    “key”: “field_582a1c98459f8”,
    “label”: “Presenter Bio”,
    “name”: “presenter_bio”,
    “type”: “textarea”,
    “instructions”: “”,
    “required”: 0,
    “conditional_logic”: 0,
    “wrapper”: {
    “width”: “”,
    “class”: “”,
    “id”: “”
    },
    “default_value”: “”,
    “placeholder”: “”,
    “maxlength”: “”,
    “rows”: “”,
    “new_lines”: “wpautop”,
    “readonly”: 0,
    “disabled”: 0
    }
    ]
    }
    ],
    “location”: [
    [
    {
    “param”: “options_page”,
    “operator”: “==”,
    “value”: “presenters”
    }
    ]
    ],
    “menu_order”: 0,
    “position”: “normal”,
    “style”: “default”,
    “label_placement”: “top”,
    “instruction_placement”: “label”,
    “hide_on_screen”: “”,
    “active”: 1,
    “description”: “”
    }
    ]

  • Hi @antsykes95

    In this case, I think you can modify the code I gave you before to something like this:

    // this data is retrieved dynamically
    $current_dj = "current dj name";
    
    $repeater_value = get_field('presenter_list', 'option');
    
    foreach( $repeater_value as $row ){
        if( $row['presenter_name'] == $current_dj ){
            echo $row['presenter_bio'];
            echo $row['presenter_image'];
        }
    }

    But just as you said, I believe the best way to achieve it is by using a custom post type instead.

    I hope this makes sense 🙂

  • Ah this did the trick! Rather tedious but saves time to remake! Thanks James!

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

The topic ‘Pulling in single data’ is closed to new replies.