1

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?

Cray
  • 5,307
  • 11
  • 70
  • 166
alorange
  • 41
  • 4
  • 1
    You can do it like this: . But please add more details like the name of your ACF field and the HTML code of your table – Cray Oct 12 '22 at 05:30
  • The name of the field : sqr Html table simple with tr and td, or I can create table with table in Avada theme builder if that is better. I was try with the code you have sent, but in hrml, when I save, it disapeared. – alorange Oct 12 '22 at 12:29
  • So you want to add the field data in the editor not in a theme file? – Cray Oct 12 '22 at 13:37

2 Answers2

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

Cray
  • 5,307
  • 11
  • 70
  • 166
  • I want that to use on the product page template – alorange Oct 12 '22 at 14:03
  • I've changed my answer – Cray Oct 12 '22 at 14:12
  • @alorange please make an extra question for that. You can link it here so I will check. And please add some code samples and an description what you want to achieve – Cray Oct 12 '22 at 15:08
  • Okay, answered it there. Please delete the comments here for a cleaner/better experience on the site. I will do the same. And if you don't mind, you can upvote my answer if it helps you ;) – Cray Oct 12 '22 at 16:00
1

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

C0G1T0
  • 350
  • 1
  • 5
  • 17