• Resolved phantasmix

    (@phantasmix)


    I want to use the role filter like this:

    <?php echo do_shortcode( '[members_access role="' . echo $roles; '"]' ); ?>

    where $roles come from an Advanced Custom Fields Repeater. Doesn’t seem to work though. Everything else works, but not when I wrap it all up in do_shortcode. Can this shortcode be called like this?

    Thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter phantasmix

    (@phantasmix)

    Really helps to talk it out sometimes ??

    There was a typo and an unnecessary ‘echo’. So here’s the working line:

    <?php echo do_shortcode( '[members_access role="' . $roles . '"]' ); ?>

    Thread Starter phantasmix

    (@phantasmix)

    Spoke too soon. It doesn’t break the page, but the shortcode isn’t filtering the content based on the role, and I’ve got a stray tag showing from the closing do_shortcode

    [/members_access]

    Thread Starter phantasmix

    (@phantasmix)

    ——-

    Simplest way to do this with Members:

    
    <?php if ( is_user_logged_in() && members_user_has_role( get_current_user_id(), $roles ) ) : ?>
    
    	HTML goes here.
    
    <?php endif; ?>
    

    I’m assuming $roles is an array of roles.

    ——

    Shortcodes aren’t really a great way to do things like this. Use PHP instead.

    Thread Starter phantasmix

    (@phantasmix)

    Thanks. That’s the direction I went in with the last (edited) message ??

    Though still stuck, I suspect it’s to do with ACF now, because $roles is a repeater checkboxes field and I always get stuck at those.

    Thank you for your help, I’m sure once the ACF thing is figured out, the above will work.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘echo do_shortcode?’ is closed to new replies.