$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>custom taxonomy - Get post meta value outside of the loop|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

custom taxonomy - Get post meta value outside of the loop

matteradmin9PV0评论

I'm working on an extra function to list different stuff,

My function looks like: "display all hotels for a specific city" -> hotels is as CPT and CITY as custom Tax. So for exemple, lets display all hotels in Paris.

function test($cpt,$taxonomy = 0) {
   $args (...)
   $query (...)
   while {...}
}

So I go to query different custom posts types, with or without a taxonomy. Until here, everything is OK.

But is it possible to get some data from this $taxonomy (city/paris) without creating a new query? Like I want to get custom field called "area_singular" linked to the $taxonomy passed in the function? The title of it, etc.?

P.S. The value of $taxonomy is passed by

$term = get_queried_object();
test('custom_post',$term);

P.P.S. Actually i have an other function, where i pass this custom field, & title in the function like test('cpt',$term,$custom_field,$title); but I'm sure there is a way to get the data without passing them by the function.

EDIT: With $taxonomy->post_title I can get the title, so how can I get the custom field the same way?

I'm working on an extra function to list different stuff,

My function looks like: "display all hotels for a specific city" -> hotels is as CPT and CITY as custom Tax. So for exemple, lets display all hotels in Paris.

function test($cpt,$taxonomy = 0) {
   $args (...)
   $query (...)
   while {...}
}

So I go to query different custom posts types, with or without a taxonomy. Until here, everything is OK.

But is it possible to get some data from this $taxonomy (city/paris) without creating a new query? Like I want to get custom field called "area_singular" linked to the $taxonomy passed in the function? The title of it, etc.?

P.S. The value of $taxonomy is passed by

$term = get_queried_object();
test('custom_post',$term);

P.P.S. Actually i have an other function, where i pass this custom field, & title in the function like test('cpt',$term,$custom_field,$title); but I'm sure there is a way to get the data without passing them by the function.

EDIT: With $taxonomy->post_title I can get the title, so how can I get the custom field the same way?

Share Improve this question edited Mar 10, 2019 at 10:54 Max Yudin 6,3982 gold badges26 silver badges36 bronze badges asked Mar 9, 2019 at 19:17 GregoryGregory 6025 silver badges20 bronze badges 3
  • Your question is a bit unclear. Are you trying to get the value of a field attached to a custom taxonomy term? Example: advancedcustomfields/resources/adding-fields-taxonomy-term/… – MikeNGarrett Commented Mar 9, 2019 at 19:31
  • Hello, yes, it is a custom taxonomy term. Its like, "i want to display all hotels from paris" ( hotels = cpt, paris = custom tax). But before i make my query + while, i want to display a custom field, linked to paris. Is this more clear ? – Gregory Commented Mar 9, 2019 at 19:35
  • ok, i arrive to get title with $taxonomy->post_title. Now i need to get my custom field and it will be perfect ^^ – Gregory Commented Mar 9, 2019 at 21:17
Add a comment  | 

1 Answer 1

Reset to default 1

According to the ACF documentation on getting field data from fields attached to terms, you want to do something like this:

$term = get_queried_object();    
$area_singular = get_field( 'area_singular', $term );
Post a comment

comment list (0)

  1. No comments so far