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?
- 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
1 Answer
Reset to default 1According 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 );