Advanced Custom Fields do not appear on the front end

Asked

Viewed 1,837 times

3

I’m having a problem with the plugin ACF (Advanced Custom Fields) for Wordpress, I even paid the $25 for the add-on Repeater Fields , but I don’t know if I made a good deal. I looked at the documentation and it says I just need to enter the following code: <?php the_field('NOME DO CAMPO AQUI'); ?> , but it doesn’t appear on the front end. You’ve been through this trouble?

Here it works:

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

Here he no longer accepts the code:

inserir a descrição da imagem aqui

I don’t use "templates", I write all HTML and insert PHP, I also try to use the minimum possible plugins.

inserir a descrição da imagem aqui

  • 1

    To try to play and locate the problem you better show the actual code you are using and a screenshot of your Field setup in the backend. The igrossiter solution below is cool, I remember once having needed to use something similar. It’s been a while since I work with this, but I think the Repeater Fields has a different access mode. . . . Just to make a doubt: if you disable all other plugins and use a default theme, the problem continues?

  • I disabled "all", yet it didn’t work. I’m inserting the prints below.

  • Here it works: ! [insert image description here][1] ! [insert image description here][2] Here it no longer accepts code: ! [insert image description here][3] I don’t use "templates", write all HTML and insert PHP, I also try to use the minimum possible plugins. ! [inserir a descrição da imagem aqui][4]&#xA;&#xA;&#xA; [1]: http://i.stack.imgur.com/mXDxz.jpg&#xA; [2]: http://i.stack.imgur.com/b8dWJ.jpg&#xA; [3]: http://i.stack.imgur.com/vlPzI.jpg&#xA; [4]: http://i.stack.imgur.com/21mHD.jpg

  • 1

    It’s better to post pure code than code images, using comments in HTML or PHP to indicate problematic points. And instead of adding information in the comments, [Edit]and the question to improve it.

  • 1

    In your example (where you don’t accept code) I don’t see you using the Repeater Field syntax.

  • I didn’t really use Repeater Field, I’m having trouble making the loop work so I tried an "alternative" that also didn’t work very well.

  • Well, if the answer from igrossiter doesn’t solve the problem, or if you want to make the ACF work, I suggest you edit your question considering the following: What a person needs to reproduce their problem? 1) Code that can be copied (not images) and where to insert it. 2) A display of your Field settings (yes images): /wp-admin/edit.php?post_type=acf

Show 2 more comments

2 answers

2

Advanced Custom Fields saves the fields as custom Fields normal Wordpress. With the ID of post and the code of custom field use the function 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 function into my functions.php:

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

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

That way I can use us loops:

$minha_opcao = getDados('codigo_do_campo');
  • A good option, but in case I "need" to use the ACF plugin because it was made an investment $$$ in it.

  • the ACF right..., sorry I can’t help you with it.

1

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

  • Thank you Erlon, your comment made me realize that I was not linking the "fields" to the correct pages.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.