• Resolved davidjmurray

    (@davidjmurray)


    Hi,

    If I use ACF to add a repeater field to the user form, I cannot inform the repeater that the field is a user field.

    e.g.

    [repeater user_field=events_attended]
    [user event_date]
    [user event_name]
    [/repeater]

    So, I want to have a repeater group for events (seems to be a common theme in support these days) with sub fields of date and name.

    Then I want to display this on a page called my-account (wooCommerce).

    I had a look at the repeater code in the /optional/acf.php and there is no parameter option within the CSS_TO_ACF class so I am sorta stuck.

    Any suggestions for a work around?

    Thanks in advance for any suggestions.

    Cheers,
    djm

Viewing 5 replies - 1 through 5 (of 5 total)
  • Have you tried if you have to? What happens if you call them without user_ and later as field instead of user.

    • This reply was modified 4 years, 4 months ago by polarracing.
    Thread Starter davidjmurray

    (@davidjmurray)

    Thanks polar but I have tried that and the field shortcode does not read from the user info and the user info is not a valid post type so it’s not possible to ‘trick’ it that way.

    So I used the Kobayashi Maru solution.

    I found a rather useful undocumented shortcode called [x] which is used as:

    [x max-loops] 
    [/x]

    where max-loops is the number of times to loop.

    A variable {X} is available within the tags which displays the loop counter:

    [x 5]
    {X}
    [/x]

    displays:
    12345

    Also, as the ACF repeater data is stored as individual metadata fields and not an array then my complete solution is:

    [set maxevents] [user events_attended] [/set]
    [ul]
    [pass vars]
    [x {MAXEVENTS}]
    [li] [user events_attended_{X-1}_event_date] - [user events_attended_{X-1}_event_name]
    [/li]
    [/x]
    [/pass]
    [/ul]

    Oh, I had to modify the code in the modules/format.php to get the loop counter to start at zero rather than one:

    $rendered = str_replace('{X}', $i, $content);
    $rendered = str_replace('{X-1}', $i - 1, $rendered);

    because the [pass vars] cannot be nested somehow…

    Yer, I do that sometimes….

    [pass vars] can be nested with [-pass vars]. To address a variable created within the first [pass vars] use {-VARIABLE}.

    Thread Starter davidjmurray

    (@davidjmurray)

    Polar,
    Thanks for your help.

    I missed that little tipbit at the bottom of the pass doc page; though I thought that I tried that combination.

    Therefore, I’m back to method B (or was it C?).

    [set maxevents] [user events_attended] [/set]
    [ul]
    [pass vars]
    [x {MAXEVENTS}]
    [set xx] [calc] {X} - 1 [/calc] [/set]
    [-pass vars]
    [li] [user events_attended_{-XX}_event_date] - [user events_attended_{-XX}_event_name]
    [/li]
    [/-pass]
    [/x]
    [/pass]
    [/ul]

    and now I no longer depending on my monkey patching to the format.php code.

    But I might add a separate shortcode with an offset attribute to my snippets collection as it might come in handy:

    [xloop max=5 offset=-1]
    {X}
    [/xloop]

    Simple and useful I think.

    Cheers,
    djm

    • This reply was modified 4 years, 4 months ago by davidjmurray.
    • This reply was modified 4 years, 4 months ago by davidjmurray.

    Remember, you can use meta shortcodes for functions you use all over the place.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Repeater does not work with ACF repeater group on current user info’ is closed to new replies.