Home > database >  Add ACF in table wordpress
Add ACF in table wordpress

Time:10-13

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?

CodePudding user response:

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

CodePudding user response:

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

  • Related