79243613

Date: 2024-12-02 10:06:46
Score: 1.5
Natty:
Report link

How do I get the ACF field value from the category?

For a category:

<?php
$post_id = "category_3"; // category term ID = 3
$value = get_field( 'my_field', $post_id );
?>

For a custom taxonomy "event":

<?php
$post_id = "event_4"; // event (custom taxonomy) term ID = 4
$value = get_field( 'my_field', $post_id );
?>

Samples taken as is from acf get_field() docs: ACF get_field() documentation

All the samples:

<?php
$post_id = false; // current post
$post_id = 1; // post ID = 1
$post_id = "user_2"; // user ID = 2
$post_id = "category_3"; // category term ID = 3
$post_id = "event_4"; // event (custom taxonomy) term ID = 4
$post_id = "option"; // options page
$post_id = "options"; // same as above

$value = get_field( 'my_field', $post_id );
?>
Reasons:
  • Blacklisted phrase (1): How do I
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): How do I
  • Low reputation (0.5):
Posted by: DrLightman