Hi
I’m having trouble getting a taxonomy term to display.
I use the Salient Theme with portfolio post type.
The taxonomy is generated by the portfolio post type.
I use this: https://www.advancedcustomfields.com/resources/taxonomy/
Return Value > Term ID can be displayed.
Return Value > Term Object can not be displayed (breaks my site).
I found this:
By default ACF stores Taxonomy field values as a serialized array of taxonomy term IDs in the database. ACF allows you to specify a return type (e.g. Term Object) in the settings, but because only the term IDs are stored in the database, only those IDs will be indexed by default.
So, I need to tell my theme to instead index what ACF works with, right?
I found a similar topic here.
Unfortunately PHP is not my forte and help is highly appreciated.
Thanks
I have a repeater in Woocommerce categories where the admin can select categories.
I have chosen Term ID and can output the chosen image and URL, but I can’t seem to get the term name.
I’ve tried;
<?php echo esc_html( $post_id->name ); ?>
<?php woocommerce_page_title($post_id); ?>
<?php echo $post_id->cat_name; ?>
<?php echo '<p>'. get_the_category( $post_id )[0]->name .'</p>'; ?>
<?php echo esc_html( $post_id[0]->name ); ?>
None work…..
Anyone got any ideas, please?
Since 3 days !!! I try to have show only the select taxonomies and tag taxonomies that have a post, but I
Example. In a correct loop in home page IÂŽm showing all posts categories XXX like this (and itÂŽs working and not problem with that):
CATEGORY 1
Title
Img
FiedText
(and here I want the list of select taxonomies/tag-taxonomy-1 â tag-taxonomy-2 have current post and not showing all the taxonomies and all the tags taxonomies)
Example: if I have 2 taxonomies. Monuments and gastronomy.
In Monuments taxonomy, I have tags: houses, churchs, temples, etc. And choose only Monuments Taxonomy for this pots and only one tag churches.
We will see
CATEGORY 1
Title
Image
Field text
Monuments houses, churches, temples â Gastronomy Wine, food, meat, vegetable
and i want :
CATEGORY 1
Title
Image
Field text
Monuments/churches
Someone can help me and put example code php and twig. IÂŽm so tired donÂŽt find the soluce.
Hi everyone,
I am trying to create a query based on the taxonomy field. To give a bit of background, I have an internal links CPT with the taxonomy field, which pulls from the regular post categories. This is used to create a block of internal links which will be displayed on blog posts. My code will check the post category/categories and then find links that have been assigned with that post category.
$internal_links = get_posts( array(
'post_type' => 'bf_internal_links',
'meta_query' => array(
array(
'key' => 'categorieen',
'value' => '1',
'compare' => 'LIKE'
),
)
) );
Here’s how I am getting the links. I thought that I’d be able to put the actual category name under value, but that doesn’t work. When I checked the database I see no words under value at all, just “1” and that query does work. The aim here is to use an array populated by a variable that holds the current post category/categories.
I must be missing something. đ Thanks in advance for helping me with this.
I’m struggling to populate ACF product_tag taxonomy images into product pages. Each product may be assigned to 1 or more product tag. I’d like to display those images and make the link to their archive pages.
I have this code but it is only showing the word “Tag”. Can’t make it pull the images:
add_action('woocommerce_before_add_to_cart_form','finish_image',22);
function finish_image() {
global $product;
$terms = get_the_terms( $product->get_id() , 'product_tag' );
if($terms) {
foreach( $terms as $term ) {
$image = get_field('tag-image', $term->term_id);
print_r($image);
echo 'Tag <img src="'.$image.'" alt="" />';
}
}
}
So I want to create a true relationship between 2 custom post types. Something similar what would be done with MySQL way, having a primary and secondary key. I want to have something like one to many.
I have two custom posts. Artist and Event.
Artists have their own fields, events as well. Thing is. If I create with taxonomies and put fields from artists under events, events would have those taxonomies and that would work fine. For an example location. When you go to events/locations/ you can see those. However. I need things to be mainly set to Artist (CPT) and on Event CPT to select Artist.
But then, event is in relation to that Artist and has things related to Artist (location, genre and similar). In this case artist bcs of those fields (taxonomies) would have those taxonomy/category/archive pages, but I need them for the events as well.
Example: Artist X is placed inside genre music. Event X is created, I select Artist X, now this event has automatically genre music. Now Artist has URL artist/genre/music but event as well event/genre/music.
I know about the post object and relation field, but not sure is it the right way as I think a proper way exist.
Any help, would be appreciated. Thanks
Either I’m daft or I’m trying to do more than is possible, let’s see which đ
I have a custom posttype: ‘podcasts’
This custom posttype has two custom taxonomies via ACF: ‘Shows’ and ‘Topic’.
Topic is standalone taxonomy on posts, but is also applied to ‘Shows’ as a field (see screenshot).
Making the right topics display on page alongside relevant ‘Shows’ was fairly trivial, but I cannot for the life of me figure out how to go the other way and display a list of ‘Shows’ based on a specific ‘Topics’.
For example I have /shows/sometitle/
On that page I can easily display Show sometitle, with Topics A, B and C beside it and the relevant posts in the Show taxonomy beneath. I can do the same with other Shows.
But I cannot seem to create /topics/nature/ and display Topics nature, with Show A, Show B, Show D beside it (perhaps Show C has a different topic).
Is there a way to display the a taxonomy (shows) only when a specific second taxonomy name is also present (topics=nature)?
Hopefully I’ve made sense, perhaps I’m going about this all wrong and there’s a better route to take?
On the Edit-Tags.php page – Iâve added a ACF Checkbox (True/False) for any tags in this Custom Taxonomy. Iâve also included the ACF Field in the Columns.
So currently the only way to change the ACF Checkbox value is to actually edit the tag. Which works but not the ideal user experience.
The goal is to be able to edit the ACF Checkbox Value using the Quick Edit feature in WordPress.
I did find a good starting tutorial:
https://wordpress.stackexchange.com/questions/139663/add-description-to-taxonomy-quick-edit
Though Iâm struggling with saving the value specifically for the ACF Field.
Has anyone done this before or has any insight?
Appreciate all the help the Forum provides.
I want to create a repeater field inside a group field. The repeater is to be used to output a customized category list with the use of a taxonomy field.
Group
– Repeater
— Taxonomy
It is not about the structure in the ACF backend, but about the concept of the code. I have been through so many code variations up to this point that I don’t want to post any code here for now, but ask for the best practice for this task.
The goal is to allow the user to build a list of existing categories and sort them. The list will be given a heading, which is why I want to put this in a group.
In the frontend, a simple list of categories is displayed.
Thanks a lot for your support!
I’m trying display specific custom post types by taxonomy on specific pages, and I’m attempting to follow in the footsteps of the advice found here: https://support.advancedcustomfields.com/forums/topic/query-posts-via-taxonomy-field/
I’ve associated the custom post type taxonomies with the pages via the Taxonomy ACF field, and I’ve got that working fine.
However I’m wondering if it’s possible make it so that I can divide the out put up by those taxonomies, similar to the solution found here:https://wordpress.stackexchange.com/a/40117
But I can’t seem to successfully figure out how to marry the two concepts, so that the end result is that I’m only displaying the specific custom posts that relate to the taxonomies that I’ve selected on the target page via the Taxonomy field, separated by one of those taxonomies.
Below is my unsuccessful attempt:
<?php
$post_id = $post->ID;
$domains = get_field('matrix_domain', $post_id);
$grades = get_field('matrix_grades', $post_id);
if (!is_array($domains)) {
$domains = array($domains);
}
if (!is_array($grades)) {
$grades = array($grades);
}
$terms = get_terms( array(
"taxonomy" => "math_grades",
) );
foreach ($terms as $term) :
$posts = get_posts( array(
'post_type' => 'math_matrix',
'posts_per_page' => -1, //important for a PHP memory limit warning
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'math_domains',
'terms' => $domains,
),
array(
'taxonomy' => 'math_grades',
'terms' => $grades,
),
),
));
?>
<h4><?= $term->name; ?></h4>
<div class="matrix-labels"><div class="standard-label">Standard</div><div class="can-label">Can the student:</div><div class="cannot-label">If not:</div><div class="resource-label">Additional Resource</div></div>
<ul class="matrix-search">
<?php foreach($posts as $post) : ?>
<li><div class="matrix-standard"><div class="mobile-label">Standard</div><?php global $post;
$standards = wp_get_post_terms($post->ID, 'math_standards', array("fields" => "names"));
if (count($standards) > 0)
{
echo implode(', ', $standards);
}; ?></div>
<div class="matrix-title"><div class="mobile-label">Title</div><?php the_title(); ?></div>
<div class="matrix-action"><div class="mobile-label">Action</div><a>" target="_blank"><?php echo esc_html($actionsTitle); ?></a></div>
<div class="matrix-resource"><div class="mobile-label">Additional Resource</div><a>" target="_blank"><?php echo esc_html($resourcesTitle); ?></a></div>
</li>
<?php endforeach; ?>
</ul>
<?php endforeach; ?>
<?php
$post_id = $post->ID;
$domains = get_field('matrix_domain', $post_id);
$grades = get_field('matrix_grades', $post_id);
if (!is_array($domains)) {
$domains = array($domains);
}
if (!is_array($grades)) {
$grades = array($grades);
}
$_terms = get_the_terms( $post_id , 'math_grades' );
foreach ($_terms as $term) :
global $post;
$_posts = new WP_Query( array(
'post_type' => 'math_matrix',
'posts_per_page' => -1, //important for a PHP memory limit warning
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'math_domains',
'terms' => $domains,
),
array(
'taxonomy' => 'math_grades',
'terms' => $grades,
),
),
));
if( $_posts->have_posts() ) : ?>
<h3 class="grade"><?php echo $term->name; ?></h3>
<div class="matrix-labels"><div class="standard-label">Standard</div><div class="can-label">Can the student:</div><div class="cannot-label">If not:</div><div class="resource-label">Additional Resource</div></div>
<ul class="matrix-search">
<?php while ( $_posts->have_posts() ) : $_posts->the_post();
?>
<li><div class="matrix-standard"><div class="mobile-label">Standard</div><?php global $post;
$standards = wp_get_post_terms($post->ID, 'math_standards', array("fields" => "names"));
if (count($standards) > 0)
{
echo implode(', ', $standards);
}; ?></div>
<div class="matrix-title"><div class="mobile-label">Title</div><?php the_title(); ?></div>
<div class="matrix-action"><div class="mobile-label">Action</div><a>" target="_blank"><?php echo esc_html($actionsTitle); ?></a></div>
<div class="matrix-resource"><div class="mobile-label">Additional Resource</div><a>" target="_blank"><?php echo esc_html($resourcesTitle); ?></a></div>
</li>
<?php
endwhile;
echo '</ul>';
endif;
wp_reset_postdata();
endforeach;
?>
Hi all,
I’m tearing my hair out over this. I’m staring at my code trying to work out where I’m going wrong, and I’m having difficulties picking it.
I’m trying to update the sidebar of my theme to display the contents of the fields I have set up. The logic I’m trying to set up is that it only displays details about a field if it contains a value, and ignore empty fields. I’ve got that working with the URL fields and Text fields. However I’m having issues with the Taxonomies.
I’m using the following code:
$terms = get_field( "genre", $post_id );
if( $terms ) {
echo "<b>Genre:</b> ";
foreach( $terms as $term ) :
echo esc_html( $terms->name );
endforeach;
echo "<br />";
}
The issue that I’ve got is that it displays the “Genre:” label, so it is obviously correctly picking up a value. IT doesn’t actually display the value of the field though.
I was attempting to base this off https://www.advancedcustomfields.com/resources/taxonomy/ to try and work out how to use this correctly.
I’m tearing my hear out trying to work out what I’m doing wrong. I’m sure it’s something dead simple that I’m not getting out of frustration. Hopefully somebody is able to offer some pointers as to what I’m doing wrong.
Hello,
I’m using several ACF Taxonomy select fields in an ACF group.
They work quite well except that they load options very slowly.
I played around with some extensions which have similar fields but slightly different options. In the end I noticed that, if I disable AJAX / Lazy loading in specific fields of those plugins, their options are loaded much faster, and now I’m wondering if I can do something similar with ACF.
I’d like to keep ACF default Taxonomy field because it gives me the chance to add a new value for that specific tax on fly, but I’d love to know if/how can I turn off AJAX Lazy loading for all my select2 fields.
Thank you!
I would like to display a brand logo on my product pages. I use Advanced Custom Fields (ACF) to insert the image on the taxonomy “Brand”.
https://snipboard.io/JcYvM4.jpg
I have tried the code below, and tried to do as on the page here, but it doens’t work…
https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
*The image return format is “Array”.
Here is my code:
function action_woocommerce_before_variations_form( ) {
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$image = get_field('brand_logo', $taxonomy . '_' . $term_id);
echo '<img src="'.$image['url'].'" />';
};
// add the action
add_action( 'woocommerce_before_variations_form', 'action_woocommerce_before_variations_form', 10, 0 );
I really hope someone can help!
For some reason, I cannot get my taxonomy field to return anything within a nested WP_Query loop. I have a field-and-discipline taxonomy field on Staff custom post types. When I bring up a Staff in a WP_Query loop, I can recall any field I want from that post, except a taxonomy field.
$args = array(
'post__in' => $staffID,
'posts_per_page' => -1,
'post_type' => 'staff'
);
$staffProfiles = new WP_Query($args);
if($staffProfiles->have_posts()):
while ($staffProfiles->have_posts()) : $staffProfiles->the_post();
$id = get_the_ID();
$staffTitle = get_field('title', $id);
$staffName = get_the_title();
$discipline = get_field('teaching_disciplines', $id);
print_r($discipline); // Returns nothing
endwhile;
endif;
wp_reset_postdata();
Not sure what I’m overlooking here. It works perfectly fine in the loop.
Hello everybody. I have registered a taxonomy for example: «authors». I have two custom fields registered. One of them is «author», which the type of the field is taxonomy (authors). The other taxonomy is called “about another author” and thĐ” type of thĐ” field is taxonomy (authors) too.
The problem is that when I select the author of an article, the «about another author» custom field (that the article about him) is populated with the value of the “author” custom field.
How to solve this issue?
P.S: The name of the taxonomy isn’t «authors». WP did not allow me to use this name.
How do you target the sub-fields inside a repeater field, so the JS applies to the sub-field when appending new groups???
Been looking, but I got really lost as to where even to start. And the JavaScript API is falling a little short on explaining how to work with repeaters.
I’m working on a form to add orders for a bakery. The form has a repeater which holds the options for each different bread order. In here the select field for TYPE OF DOUGH does much of the pre-selection for the other fields (size, shape, extras).
I’ve managed to target the select field of TYPE OF DOUGH to send and modify data through AJAX, but when adding another repeater row the code doesn’t work.
Here’s my code for php and js:
JS
jQuery(document).ready(function ($) {
// field key for TYPE OF DOUGH select field inside repeater field
var field = acf.getField("field_609b103fcd576");
field.on("change", function (e) {
var value = field.val();
console.log(value);
var data = {
"action": "get_size_options",
"type_of_dough": value,
};
$.ajax({
url: ajax_object.ajax_url,
type: "post",
data: data,
dataType: "json",
success: function (data) {
console.log(data);
},
});
});
});
PHP
// enqueue the scripts
function fw_acf_register_scripts() {
// enqueue js file with ajax functions
wp_enqueue_script(
'acf-ajax-script',
get_template_directory_uri() . '/assets/js/autopopulate.js',
['jquery']
);
wp_localize_script(
'acf-ajax-script',
'ajax_object',
['ajax_url' => admin_url('admin-ajax.php')]
);
}
add_action('acf/input/admin_enqueue_scripts', 'fw_acf_register_scripts');
// ex. function to get options for the other fields
function get_size_options() {
$meta_value = fw_get_term_id($_POST['type_of_dough'], 'dough');
// just a function to get the ID for the taxonomy from the slug,
// so it just returns a number, say 501 which is then used for the term query
$size_options = array();
$terms_args = array(
'taxonomy' => 'size',
'hide_empty' => false,
'meta_key' => 'tax_position',
'orderby' => 'tax_position',
'order' => 'ASC',
);
if ($meta_value_masa) {
$terms_args['meta_query'] = array(
array(
'key' => 'dough',
'value' => $meta_value,
'compare' => 'LIKE',
),
);
}
$terms = get_terms($terms_args);
foreach ($terms as $term) {
$size_options[$term->term_id] = $term->name;
}
wp_send_json($size_options);
die();
}
add_action('wp_ajax_get_size_options', 'get_size_options');
Hi,
I have a custom taxonomy ‘dates’ and a date picker field added to all terms in that (location is set to Taxonomy -> Dates). I’m trying to convert the stored date into a timestamp. I found a great method for converting all date picker fields and it works great for fields that are attached to custom posts, but it doesn’t work for term fields. So I’ve been trying to figure out how to edit the update_field and load_value functions to work with this.
This is always loading the field as August 25 1971 after saving it correctly.
function save_as_wp_date( $value, $term_id, $field ) {
if( $value ) {
$value = strtotime( $value );
}
return $value;
}
add_filter('acf/update_value/type=date_picker', 'save_as_wp_date', 10, 3);
function load_as_acf_date( $value, $term_id, $field ) {
if( $value ) {
$value = date( 'Ymd', $value );
}
return $value;
}
add_filter( 'acf/load_value/type=date_picker', 'load_as_acf_date', 10, 3 );
What am I doing wrong with this? Any help would be welcome, thanks
I have been using the now deprecated Dynamic Posts Widget. I am trying to convert over to Dynamic Posts V2 as suggested. I have a page that uses the filter buttons provided by V1 to filter my posts. There is a button in the Render tab to turn on those filter buttons. I see no similar option in any of the tabs for Dynamic Posts V2. Ami I missing something?
Hiho,
I built a custom post type with two taxonomies (âumsaetzeâ and âsortimenteâ). Both by plugin (my own plugin, I mean, instead of by theme). Both taxonomies are set in the post type args:
âtaxonomiesâ => array( âsortimenteâ, âumsaetzeâ ),
And the registration of the taxonomies look like this:
register_taxonomy(âsortimenteâ,array(âphy_shop_offersâ), array(
âhierarchicalâ => true,
âlabelsâ => $labels,
âshow_uiâ => true,
âshow_in_restâ => true,
âshow_admin_columnâ => true,
âquery_varâ => true,
ârewriteâ => array( âslugâ => âsortimentâ ),
));`
Itâs my first plugin, so I hope this is correct.
Now:
I want users to submit their data through a cf7 form and wordpress to create posts of the custom post type when the form is submitted.
So far everything works like a charm! Everything is stored in the right custom field and I am happy, BUT ONLY:
I canât get the data of the two fields âsortimenteâ and âumsaetzeâ to fill into the taxonomies. If I map the data to ânormalâ text custom fields, the data is saved. If I map the two cf7 fields to the two custom taxonomy fields, nothing is saved, the taxonomy stays empty.
In the field set I activated âBegriffe erstellenâ (create terms?), âBegriffe speichernâ (safe terms), âBegriffe ladenâ (load terms) for the taxonomy fields [sorry, I see only the german labels and the strings differ a bit from what is shown at https://www.advancedcustomfields.com/resources/taxonomy/%5D
For the form I map the cf7 field to taxonomy fields.
What also irritates me is: when opening on of the created posts I see the two fields in two places: As select fields in the field set plus in the taxonomy boxes in post sidebar:
https://physalia.de/images/Screenshot_20210428_154332.png
Both are empty, the fields in the field set and the taxonomy fields in the sidebar. The content of the cf7 form is not inserted.
Where is my mistake?
Thanks a lot for your help.
Best regards
nici-
The page I need help with: https://unstraublich.de/offer/
As the title states: When you add a custom field and make it’s location to a ‘Taxonomy’…the field shows up twice when editing a term that belongs to said taxonomy. The issue was replicated with two different field types.
I want to add a CSS body class on every archive page of that has TRUE in an ACF implemented on each category. I added the ACF True/False to each category and I know how to use body_class filter. What I don’t get is how I can check the boolean value in the taxonomy to affect the archive page of that taxonomy.
Hi
I have a custom post type called ‘vendor’. That post type has an associated taxonomy called “filtered” and that taxonomy has a term called “enabled”. In my options page I have a post object field that lets user to select any post in the above post type. I would like to then dynamically assign the taxonomy term “enabled” to every post selected in that post object field. It should be dynamic, meaning if a post gets removed from that list, the term also gets removed from the said post.
I know it sounds like a weird way of doing things, but I’m first letting user select which items are highlighted on the site, but I want to make it an easier UIX so that they don’t need to go also assign a term for every post separately as well, but rather do that based on their selection in the post object field.
I’m not exactly sure where to even start with this so any help would be greatly appreciated, thanks!
I’m trying to list the relevant categories for a custom taxonomy when visiting a post. At the moment, I’m trying to use the below code, which currently lists all of the categories, rather than the relevant ones, and the image url is only the taxonomy ID.
Can anyone help me work out where I’ve been stupid please?
$args = array( 'hide_empty' => '0','taxonomy' => 'book_cat');
$categories = get_categories($args);
if($categories){
echo '<ul>';
foreach($categories as $category) {
$link = get_term_link($category);
echo '<li>';
$size = "thumbnail";
$image = get_field('main_image', 'category_'.$category->term_id);
echo '<img src="' . $image . '" />';
echo '<span class="cat-title"><a href="'.$link.'">' . $category->name . '</a></span>';
echo '</li>';
}
echo '</ul>';
}
Hi,
I’m looking to sort multiple posts into lists after the query.
I have to query the posts using a taxonomy term that is a field and then have all these posts sorted in different year by an other field.
I want to have lists with the year as title like this:
2021:
post
post
post
2020:
post
post
post
etc.
Here’s my code right now:
<?php $topics = get_sub_field('sous-categories-en-avant');
if ($topics) {
if (!is_array($topics)) {
$topics = array($topics->slug);
}
$args = array(
'post_type' => 'production',
'posts_per_page' => -1,
'order' => 'DESC',
'meta_key' => '_production_year',
'orderby' => 'meta_value',
'tax_query' => array(
array(
'taxonomy' => 'production-category',
'field' => 'slug',
'terms' => $topics,
),
),
);
$production_query = new WP_Query($args);
if ($production_query->have_posts()) $count = 0; {?>
<div class="grid" data-packery='{ "itemSelector": ".grid-item", "gutter": 10 }'>
<?php while($production_query->have_posts()) {
$production_query->the_post(); ?>
<?php $year = get_field('_production_year');?>
<?php if ($count > 0 && (($count % 2) == 0)) {?>
<div class="grid-item">
<?php } else{?>
<div class="grid-item grid-item--width2">
<?php }?>
<a href="<?php the_permalink();?>">
<div class="productions-archives-thumb">
<?php the_post_thumbnail( 'medium','');?>
</div>
<div class="productions-archives-text">
<?php the_title();?>
<?php the_field('_production_year');?>
</div>
</a>
</div>
<?php $count++; }?>
</div><!-- grid-->
<?php }
wp_reset_postdata();
}?>
I hope that someone can help me with this, thanks by advance, best
I’m using a repeater field on product pages to create an accordian with headings like “product specifications” and “about the manufacturer”.
I’ve created a custom taxonomy called “manufacturers” with the following custom fields:
an image field named “mft-logo” which is set to return the image url.
a text field named “mtf-location” for displaying locations i.e. “New York City, NY”
a text field named “mft-bio”
Currently, I’m having success using the following shortcodes for the “About the Manfufacturer” section of the accordian:
<img src="[acf field='mft-logo' post_id='term_44']">
Headquarters: [acf field='mft-location' post_id='term_44']
About this Manufacturer: [acf field='mft-bio' post_id='term_44']
My goal is to be able to use the taxonomy slug (for example, ‘acme-usa’) instead of the post_id to expedite the work being done by product editors. It’s much easier for them to add a slug name (which will always be the name of the company using dashes instead of spaces) rather than manually looking at the backend of each manufacturer page to find out the post_id number.
For example:
<img src="[acf field="mft-logo" post_id="acme-usa"]>
Headquarters: [acf field="mft-location" post_id="acme-usa"]
About this manufacturer: [acf field='mft-bio' post_id='acme-usa']
Is there any way to do this using slugs?