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.
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.
also works fine for me
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?
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()
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.
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.
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 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.
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
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.
I think it will be on wordpress.tv… I’ll post it up here when it happens!
WordPress.tv is great but sometimes overwhelming with the amount of videos there
@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.
<?php $ckey = 'show_carousel'; if (get_field($ckey)) : ?> <?php get_template_part('templates/carousel'); ?> <?php endif; ?>
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.
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.
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.
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.
@cwulff, gimme a few hours and I’ll post up a kickass post with some info for ya.
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?
Hope it helps. Let me know if you have any questions…
Amazing! Thanks so much for sharing this.
Sorry I mess up.
You must use a template for ACF ?
Because for my home statique
1/I create "base-front-page.php
inside I just copy base.php
<?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 ?