N
N
NFI2018-05-06 15:48:52
WordPress
NFI, 2018-05-06 15:48:52

Why does a custom field return 0?

Good afternoon, tell me what I'm doing wrong
On the site, each heading will have its own picture inserted, which relates to the subject of this heading
Created a custom field using the Advanced Custom Fields plugin so that you can add pictures to the headings
in the code
joxi.ru/bmoE8O7iMRlLjA
The problem is that the picture is inserted only when the category has no entries
joxi.ru/Drlg1Okc49dRzA
As soon as I add a category entry in the url, nothing is transferred
joxi.ru/eAOzn4jT4JGRB2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Mironov, 2018-05-06
@NFI

The problem is that ACF works a little differently with category fields
. Here's off. documentation https://www.advancedcustomfields.com/resources/add...
In short:
// Need to define a variable with the current category
$term = get_queried_object();
And your code will look like this:

<?php $term = get_queried_object(); ?>
<section class="section_pict" style="background-image: url('<?php the_field('picture-rubric',$term);?>">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question