skip to Main Content

I have a text field with ACF.

On one page where I have a simple table, I want to import that ACF text into one field in the table. But not sure how to add?

2

Answers


  1. To add it in the editor:

    You can add field data with a simple shortcode. Try to add the following shortcode in your table:

    [acf field="sqr" post_id="123"]
    

    You need to change the number in post_id="123" with the actual ID from your page.

    Look in the URL field of your browser, there you should find the ID like here:

    example.com/wp-admin/post.php?post=123&action=edit
    

    Here’s more about that: Shortcode

    To add it in the product template

    Add this code to your template:

    <?php $sqr = get_field('sqr'); ?>
    

    After that you can use the following code in your table:

    <?php echo $sqr; ?>
    

    Or just use the following code (without extra variable):

    <?php the_field('sqr'); ?>
    

    Here’s more about that: get_field()

    Login or Signup to reply.
  2. If you want to use the value of an ACF field, you can use the function get_field

    $valueOfMyAcfTextField = get_field(‘name_of_the_field’);
    

    Then you can simply echo it where you want in your template:

    <?php echo $valueOfMyAcfTextField; ?>
    

    or directly like that:

    <?php echo get_field(‘name_of_the_field’); ?>
    

    Beware the name of the field is the key of the field not the title.

    Hope it helps

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search