O
O
o4ennuzhen2020-05-14 14:30:28
WordPress
o4ennuzhen, 2020-05-14 14:30:28

Doesn't display custom Advanced Custom Fields?

Guys! I've been fighting for a day now, I've tried all the probably possible Wordpress plugins for displaying custom fields and none of them outputs. Also read the ACF plugin documentation (what I could) and the answers on this site. I can't figure out what the problem is.
I took the code from the plugin documentation:

<?php 
$link = get_field('ssylka');
if( $link ): ?>
    <a class="button" href="<?php echo esc_url( $link ); ?>">Скачать</a>
<?php endif; ?>

On one site it works without questions, even with a button it displays as it should. The other one is empty. Plugin settings on both sites are the same.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Sarvarov, 2020-05-14
@megakor

So get_field is displayed not within the framework of some post. WordPress doesn't understand which post you want to get extra data from. fields.
There are two options:
1. Pass the post ID to the function, for example: get_field('ssylka', $post_id);
2. Use setup_postdata(). More details: https://wp-kama.ru/function/setup_postdata

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question