Support

Account

Home Forums Front-end Issues Shortcode doesn't work in Page

Solving

Shortcode doesn't work in Page

  • I’m still a newbie in ACF,

    I created a basic field as shown in the following screenshot:

    ACF Field

    I can see the field without any problem in User’s profile page but I failed to show the content of this field in the usual pages using this shortcode:

    [acf field="sms2"]

    How can I fix this issue?

  • Can you explain the steps that you are following?

    1) You are creating the page
    2) Editing the page using the “Text” editor (not the visual)
    3) Copying / Pasting the shortcode

    and its not working? Why is not working? What is exactly displaying?

    1. Created custom field as shown in the above screenshot
    2. Created a new page
    3. Added this shortcode through text editor because visual editor doesn’t show a button for ACF (as shown in the following screenshot)
    4. clicked publish… Voila nothing appeared!

  • @hpctech the answer is simple: In your case the ACF is empty, because there is no place so far where you are filling the information that this field should be displaying. The ACF is a “container”, but from where is this container grabbing the information that should be displayed?

    Let’s say you use a post to do this. If I am not wrong in your current settings, if you go to Posts > Add new, you will see the new sms2 field you created (below the content editor). Fill that text area with something, a number, whatever, and save it, then in the page where you are using the shortcode write [acf field="sms2"] or [acf field="sms2" post_id="524"] and replace 524 for the post-ID from where you want to grab this info.

  • May you please take a look to my screencast?

    https://vid.me/Kwsq

    I may didn’t explain the problem correctly

  • Ok, I might be wrong, but I don’t think the shortcode will let you retrieve values from a user. A shortcode only let you indicate field name and post_id.

    But this might point you out in the right direction:
    http://www.advancedcustomfields.com/resources/how-to-get-values-from-a-user/

    The documentation says:

    All the API functions can be used with a user, however, a second parameter is required to target the user ID. This is similar to passing through a post_id to target a specific post object.

    The $post_id needed is a string containing “user” + the user ID in this format: “user_$UserID”

    You will need to specifiy the user_ID for that. But as I said before, I dont think that’s available in a shortcode.

  • it depends if you have a post for every user or not.
    if yes, than it may work with this shortcode [acf field="sms2" post_id="user_1"] of course only for user 1

    if you wish to have 1 post and show value depends on user, i think, you need a custom template for that post

  • Unfortunaltely it seems that ACF will not fit my needs because I’m looking for completely dynamic solution 🙁

    BTW, I found cimy user extra fields which does exactly what I need but unfortunately it doesn’t support shortcodes (I’ve to write them manually)

  • you cant have a dynamic solution with ACF shortcodes.

    but as i write before if you create a custom template for that page.
    and use there something like that

    <?php the_content(); ?>
     <?php if ( is_user_logged_in() ) {
    $userid = get_current_user_id();
    get_userdata( $userid );  
    get_field('sms2', 'user_'. $userid );
    }?>

    of course you need to add the post loop arround, and maybe add a user-role filter too. but i hope that info help you to do it on your own

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

The topic ‘Shortcode doesn't work in Page’ is closed to new replies.