Conversation
supportI’m just stupid or but I can’t display ACF in my content-single.php (yes it is the right file I’ve already altered it a few times…) I entered this code: <?php if(is_category('bokrecensioner')) { echo '<div style="padding: 15px; border: #000 dotted;">' . '<h4 style="text-align: center;">' . 'Bokfakta' . '</h4>' . '<br>' . '<p>' . acf_get_fields('group_69c7ce7cf28f7') . '</p>' . '</div>'; } elseif(is_category('biorecensioner')) { echo '<div style="padding: 15px; border: #000 dotted;">' . '<h4 style="text-align: center;">' . 'Filmfakta' . '</h4>' . '<br>' . '<p>' . acf_get_fields('group_690cc62871539') . '</p>' . '</div>'; } elseif(is_category('teater-och-showrecensioner')) { echo '<div style="padding: 15px; border: #000 dotted;">' . '<h4 style="text-align: center;">' . 'Showfakta' . '</h4>' . '<br>' . '<p>' . acf_get_fields('group_6a185df8e8409') . '</p>' . '</div>'; } elseif(is_category('streamingrecensioner')) { echo '<div style="padding: 15px; border: #000 dotted;">' . '<h4 style="text-align: center;">' . 'Streamingfakta' . '</h4>' . '<br>' . '<p>' . acf_get_fields('group_69d41ebee596d') . '</p>' . '</div>'; } elseif(is_category('dvdbd-recensioner')) { echo '<div style="padding: 15px; border: #000 dotted;">' . '<h4 style="text-align: center;">' . 'Videofakta' . '</h4>' . '<br>' . '<p>' . acf_get_fields('group_69c7dc06b14a7') . '</p>' . '</div>'; } ?> but it doesn’t work I know I did something wrong but can’t figure it out… What I would like is to display different field group depending on which category the specific post belongs to The page I need help with: [ log in to see the link]
The function is_category() “Determines whether the query is for an existing category archive page”, while content-single.php seems like a template for single posts, so the code will have no effect. Change is_category() to in_category() , which checks if the current post is within any of the given categories, and it should work.
solved it partly (thank you @galbaras ) – now the style and h4 is diplayed but not the field Tried to change the acf_get_fields('group_690cc62871539') to get_field(‘group_690cc62871539’) Didn’t help But one step in the right direction This reply was modified 1 month, 1 week ago by Michael Lindström . This reply was modified 1 month, 1 week ago by Michael Lindström .
As you can see in the documentation , acf_get_fields() returns an array of objects. You must then loop over that array and construct a string from it. The same is true for get_fields() (see here ).
The function is_category() “Determines whether the query is for an existing category archive page”, while content-single.php seems like a template for single posts, so the code will have no effect. Change is_category() to in_category() , which checks if the current post is within any of the given categories, and it should work.
solved it partly (thank you @galbaras ) – now the style and h4 is diplayed but not the field Tried to change the acf_get_fields('group_690cc62871539') to get_field(‘group_690cc62871539’) Didn’t help But one step in the right direction This reply was modified 1 month, 1 week ago by Michael Lindström . This reply was modified 1 month, 1 week ago by Michael Lindström .
As you can see in the documentation , acf_get_fields() returns an array of objects. You must then loop over that array and construct a string from it. The same is true for get_fields() (see here ).