# Using Advanced Custom Fields Plugin

**URL:** https://discourse.roots.io/t/using-advanced-custom-fields-plugin/412
**Category:** uncategorized
**Created:** 2013-09-27T00:58:18Z
**Posts:** 27

## Post 1 by @talves — 2013-09-27T00:58:19Z

I installed Advanced Custom Fields plugin into my roots activated site. I am wondering if anyone else has tried to integrate the plugin or tried it? I am sure I need to include their api to use it in roots. Not sure best practices for doing this. For now I am just using the custom fields natively from WP that are created by ACF. This works fine as expected, but wondered how/should I hook it to the functions in ACF.

---

## Post 2 by @kalenjohnson — 2013-09-27T06:10:59Z

I use ACF and like it. Not sure what your question actually is though… if it’s how to use it in the theme, you call the custom fields directly in the template files. You should probably read up on the ACF website on how to use each one correctly.

---

## Post 3 by @fabuBaracus — 2013-09-27T08:41:41Z

also works fine for me

---

## Post 4 by @talves — 2013-09-27T15:32:21Z

When I call the ACF functions from the templates, they do not work. Do I need to include the api.php page from the plugin in the roots functions.php?

---

## Post 5 by @kalenjohnson — 2013-09-27T22:29:44Z

No, if you have the plugin installed and active, you don’t need to load anything in the theme other than calling the fields.

Unless something else is wrong, it sounds like you’re not using the plugin correctly. You DID read the developers docs? I’m going to guess you’re not using the\_field() or you’re not echoing get\_field()

---

## Post 6 by @talves — 2013-09-27T22:45:30Z

Ok, I will take another look at it and let you know what I did wrong. I was using the\_field(), but will give it another try.

---

## Post 7 by @kalenjohnson — 2013-09-27T22:56:50Z

Make sure you’re calling the name of the field exactly as well.

I really don’t know what’s going on without looking at your site, but these are some things that have messed me up on the past.

---

## Post 8 by @JulienMelissas — 2013-09-28T00:33:06Z

I **love** ACF - so much that I’ll be speaking about it at WordCamp Raleigh, NC in 2 months for the Developers Track.

I used ACF and Roots tons on [www.thomsestate.com](http://thomsestate.com) and I’m using it even more on a new one I’m developing. Never had an issue with it working with Roots.

Like @kalenjohnson said, make sure that you’re using `the_field();` correctly - it automatically echos. If you’re using `get_field();` make sure to `echo get_field()`; if you need to. Also, make sure you’re calling the fields like `the_field( 'field_name' );` or whatever. Keep in mind hyphens and underscores are different.

Because I sometimes have over 10 - 20 customs fields on a page, I set a variable for the post like `$page_info = get_fields();` and then go through that array like `$page_content = get_fields['page_content']` to get my info, that way I’m only making one DB call and I can easily set variables.

If I need to post some code so you can see it in use I’d be happy to, just lemme know.

Good luck!

---

## Post 9 by @enollo — 2013-09-28T03:09:27Z

> [@JulienMelissas](#):
>
> I love ACF - so much that I’ll be speaking about it at WordCamp Raleigh, NC in 2 months for the Developers Track.

I too love ACF and have used it extensively in both roots and non-roots themes. I would love to watch a video of the talk if it is recorded so let me know if you plan on posting it on your own website or blog so I can check in 2 months :slight_smile:

I think all the common issues I experienced when first starting with ACF have already been covered above so I cannot add value to the thread, but I am here to help if anyone have ACF related questions.

---

## Post 10 by @JulienMelissas — 2013-09-28T04:17:53Z

I think it will be on [wordpress.tv](http://wordpress.tv)… I’ll post it up here when it happens!

---

## Post 11 by @enollo — 2013-09-28T04:24:36Z

[WordPress.tv](http://WordPress.tv) is great but sometimes overwhelming with the amount of videos there :slight_smile:

Thank you!

---

## Post 12 by @talves — 2013-09-28T18:59:36Z

@JulienMelissas Here is the code I am using.

```
<?php $ckey = 'show_carousel';
if (the_field($ckey)) : ?>
     <?php get_template_part('templates/carousel'); ?>
<?php endif; ?>
```

## If I use get\_post\_custom\_values in place of the\_field, it works great. When I use the above code it puts a “1” in the place of the code, so it recognizes the value, but the output is not the template. Corrected Code

```
<?php $ckey = 'show_carousel';
if (get_field($ckey)) : ?>
     <?php get_template_part('templates/carousel'); ?>
<?php endif; ?>
```

---

## Post 13 by @talves — 2013-09-28T19:06:43Z

Stupid me. I should be using get\_field for conditional? Right? Sorry to clutter this site with this issue.

ACF is awesome! Now I can keep going and taking full advantage of it with Roots.

---

## Post 14 by @kalenjohnson — 2013-09-28T21:54:50Z

Yes, you were echo-ing the field, when you only wanted the value.

I’m sure we’ve all done it before.

Anyways, not Roots specific though, so the thread should be closed.

---

## Post 15 by @talves — 2013-09-28T22:07:00Z

No problem closing the thread, but I disagree a little with it not being Roots specific. Everyone should know the implications, if there are any of using Roots with certain plugins.

Of course, there are no implications I can see with ACF now other than I have now tied my roots template to a plugin. My original post was to ask what are the implications and best practices of using the plugin inside my roots template. :smile:

---

## Post 17 by @cwulff — 2013-12-09T20:21:37Z

Julien, I’d be interested in seeing how you simplify it down to one database call per page. I also have a few places where this would be beneficial. Many thanks.

---

## Post 18 by @JulienMelissas — 2013-12-10T22:07:06Z

@cwulff, gimme a few hours and I’ll post up a kickass post with some info for ya.

---

## Post 19 by @JulienMelissas — 2013-12-11T07:00:32Z

Dude, thanks for the inspiration to finally get my blog up and running!

I now present you with the only post on my blog. You have to start somewhere, huh?

[http://oncode.julienmelissas.com/acf-get-fields/](http://oncode.julienmelissas.com/acf-get-fields/)

Hope it helps. Let me know if you have any questions…

---

## Post 20 by @cwulff — 2013-12-15T12:31:41Z

Amazing! Thanks so much for sharing this.

---

## Post 21 by @xav — 2014-08-16T01:25:47Z

Sorry I mess up.  
You must use a template for ACF ?

Because for my home statique :frowning:

1/I create "base-front-page.php  
inside I just copy base.php

2/front-page.php  
inside:

`<?php get_template_part('templates/content', 'front-page'); ?>`

3/ in content-page-front.php, I have the code  
But I can’t use ACF ?

So, i need to create a template for this page, wich is the better way ?

---

## Post 22 by @cfx — 2014-08-17T05:11:14Z

You said you’re calling `get_template_part('templates/content', 'front-page')` but you’re calling ACF from a file called `content-page-front.php`. Try renaming that to `content-front-page.php` and call ACF functions—that’s the file `get_template_part()` is looking for.

---

## Post 23 by @ibanlopez — 2017-05-27T11:56:58Z

Hi everyone,

As that link is actually broken and the actual code data from the post is lost, for anyone interested:

[https://web.archive.org/web/20141006162633/julienmelissas.com/acf-get\_fields/](https://web.archive.org/web/20141006162633/julienmelissas.com/acf-get_fields/)

And thanks for the post @JulienMelissas by the way, very helpful even today.

---

## Post 24 by @darjanpanic — 2017-05-27T13:30:52Z

Anyone got an idea on how to lower the db queries with ACF? I know using acf-json/ kinda halves them but would be nice to lower them even further (especially if using flexible content).

---

## Post 25 by @JulienMelissas — 2017-05-27T16:36:40Z

@ibanlopez wow -it’s been a while since I’ve seen this… anyways, the page on my website seems to be working fine for me: [http://julienmelissas.com/acf-get\_fields/](http://julienmelissas.com/acf-get_fields/)

---

## Post 26 by @ibanlopez — 2017-05-27T16:52:56Z

You’re totally right @JulienMelissas. I see it now perfect.  
This morning the code just didn’t show up, so I tried to find it somehow.  
Thank u man!

---

## Post 27 by @ibanlopez — 2017-05-27T16:58:21Z

Hope this can help:

[https://www.billerickson.net/advanced-custom-fields-frontend-dependency/](https://www.billerickson.net/advanced-custom-fields-frontend-dependency/)

> **[An Alternative to ACF’s get_field()](https://www.timjensen.us/acf-get-field-alternative/)**
>
> ACF’s get_field() function is convenient, but is not always the best choice. Here I present a recursive function as an alternative to get_field().

  

> **[Performance considerations when working with ACF - Craig Simpson](https://craigsimpson.scot/performance-considerations-working-with-acf)**
>
> Advanced Custom Fields is probably my favourite WordPress plugin. For me, it unlocked the door between WordPress being a blog, and realising it’s full potential as a flexible CMS solution. It allows you to create complex pages and store data...
