Search code examples
phpwordpressfieldadvanced-custom-fields

Add ACF in table wordpress


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?


Solution

  • 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()