Fields in Advanced Custom Fields do not appear on the front end

3

I'm having a problem with the ACF (Advanced Custom Fields) plugin for WordPress, I even paid the $ 25 for the Repeater Fields add-on, but I do not know if I made a good deal. I looked at the documentation and there it says that I only need to insert the following code: <?php the_field('NOME DO CAMPO AQUI'); ?> , but it does not appear on the front end. Have you had this problem yet?

Here it works:

Here he no longer accepts the code:

Idonotuse"templates", I write all HTML and I insert PHP, I also try to use the minimum of possible plugins.

    
asked by anonymous 22.03.2014 / 03:54

2 answers

2

Advanced Custom Fields saves the fields as WordPress custom custom fields. With the post ID and custom field code use get_post_custom() :

get_post_custom($id_do_post);

For example:

$opcoes = get_post_custom(get_the_ID());
$minha_opcao = $opcoes['codigo_do_campo'][0];
// o index 0 é importante, pois get_post_custom
// retorna um array

I like to insert the following helper function in my functions.php :

function getDados($dado) {
    global $post;
    $opcoes = get_post_custom(get_the_ID());

    return $opcoes[$dado][0];
}

This way I can use loops :

$minha_opcao = getDados('codigo_do_campo');
    
22.03.2014 / 16:52
1

The example that does not work is located in the home. Your call is correct, but for it to work, you need the call on the page, be a query_posts ou the_post() .

    
24.03.2014 / 18:21