I don’t have a solution because I have not experienced the problem, but I do have some questions.
What version of PHP is running on the servers where the relationship is not saving?
Do you have an issue with other field types that save serialized data, for example multis select, taxonomy or user fields?
There are built in ways in WP for adding things like Products and Brands. These would be custom post type and custom taxonomy. Most filtering can be done using custom taxonomies for things like brands and product categories. I would start there.
ACF is great for things that would be difficult to manage using a custom taxonomy. For example, the number in stock or something like a part number associated with each product. Or for that matter, any value that would be unique, or even semi unique for each product.
You can create filters using ACF, but most of the work of building the filter/search form and the queries that display the posts for the search would need to be coded by you.
Hi John,
thanks for the example. this is the approach I eventually thought would be the case. I was going to save a taxonomy to query on eg “has_multiple” but if i can do a query on all items where meta value related_employees_count > 1 , that would do it
thanks again
J.
There isn’t any way that you can do this with one query because you are adding locations to users. I’m not even sure you could do it in one query if you were adding users to locations.
Locations added to users
Users added to locations, this would be easier
Due to the way relationship fields are stored (this includes, relationship, taxonomy, user and any field that relates one WP object to another) as serialized arrays, and the fact that you can’t really query across multiple types of WP objects (multiple post types or users/post types) there isn’t going to be a way to do this with just a WP_Query and you’re going to need to do some kind of extra work and more than likely multiple queries to make it happen.
I did some more digging and it seems that if “MY_OPTIONS” evaluates to a valid taxonomy name that your fields might be save incorrectly.
When ACF tries to figure out where it should be saving a blue it explodes the post ID resulting in
array(
'MY',
'OPTION',
'PAGE'
)
then it combines all but the last value of the array and looks to see if that is a valid taxonomy.
Anyway, I’d do a search of my database to see exactly where the values are being saved, if they are being saved at all.
I have the same issue, hence Googling and finding this.
My feeling is WP’s own “Link Manager” was depreciated because it was non-standard.
My approach is to install it for inspiration on the object design, and then use the “CPT UI” plugin to reproduce it as a Custom Post Type & Custom Taxonomy.
Maybe 30 minutes work, no code tinkering, and then you own your own Links custom object fully compatible with ACF.
Therefore achieving the same thing but without relying on any ACF mods.
Hope that helps.
It’s hard to say with the description given. Custom fields in ACF are always in a field group and they are related to some WP object, like a post type, taxonomy, user, etc. You can create options pages with ACF Pro https://www.advancedcustomfields.com/resources/options-page/ and then add groups to it. These values are stored in the WP Options table and are not related to specific WP object https://codex.wordpress.org/Function_Reference/add_option.
Custom database tables, no.
WP has custom post types https://codex.wordpress.org/Function_Reference/register_post_type. Courses, Teachers, Parents and Students would all fit nicely into custom post type. Or even Courses and “People” where People has a custom taxonomy https://codex.wordpress.org/Function_Reference/register_taxonomy to divide them into teachers, parents and students. I don’t know how much experience you have with WP, but it’s easier to work within the system it presents then to try to bend it into something else. Using custom post types and custom taxonomies you can then create the relationships that that you’re looking for.
Hi James, I saw this topic and I am facing the same issue as some others here. Maybe you can help me out too, here 😉
I have the following code:
<?php
foreach ( $terms as $term ) {
$image = get_field('berufe-thumb', $term->taxonomy . '_' . $term->term_id );
echo '<pre>';
echo "Image field value:";
var_dump($image);
echo '</pre>';
?>
The result is: Image field value:NULL
Could you have a look at it, please?
Use a custom location rule that overrides the ACF location rule for taxonomy https://www.advancedcustomfields.com/resources/custom-location-rules/
// priority 20 runs after ACF built in filter
add_filter('acf/location/rule_match/taxonomy', 'acf_location_rules_match_taxonomy', 20, 3);
function acf_location_rules_match_taxonomy($match, $rule, $options) {
if ($rule['param'] == 'taxonomy' && !isset($_GET['tag_ID'])) {
// if the rule is for taxonomy but $_GET['tag_ID'] is not set
// then this is the main taxonomy page and not a term page
// set match to false
$match = false;
}
return $match;
}
I’m glad you brought this up, there are many times when I don’t want fields to show on this page and your question made me want to figure out how to do it.
My bad. I forgot to mention (or realize) I was trying to get this to work on a custom taxonomy page, so I forgot to include get_queried_object();
Resolved now, thanks to my brain fart. Thanks for jogging my mind, John Huebner!
In case anyone else needs it, here’s my fixed code.
$queried_object = get_queried_object();
$seals = get_field('seals', $queried_object);
$countSeals = count($seals);
When getting fields from categories and other taxonomies you need to suppl the post ID. See this https://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/
Uploaded to post is something that’s built into WP. The post ID is set as the parent of the attachment. There isn’t any way to do this for options pages or for that matter, terms in a taxonomy or any other object in WP.
I do not recall any topics ever being submitted here that included a solution for this.
I’m not even sure that it would be possible at all and I’m not sure where you’d start looking. The upload uses the built in WP file upload and works through AJAX. You might be able to add some filters during the process to detect that an attachment is being uploaded for a specific options page, then you could probably add a post meta field to the attachment to indicate what it was uploaded to, and finally you could probably filter the images that are being displayed during the AJAX call that shows these images to only show others that were uploaded for the same options page. However, this is all guess work, you’re probably looking at several hours of research and testing to get each part of this working, that is if it will work, and there’s no way of knowing until you try it.
This would only work for an ACF taxonomy field and not for the standard WP category meta box.
I don’t know if you can limit the categories in the WP meta box, after a quick search I found nothing on the subject. The only thing I can find information on is how to hide it.
You can use this filter https://www.advancedcustomfields.com/resources/acf-fields-taxonomy-query/. See get terms arguments here https://developer.wordpress.org/reference/classes/wp_term_query/__construct/. You and use include to only list the ones you want or you can use exclude to eliminate the ones you don’t want.
https://support.advancedcustomfields.com/forums/topic/default-value-for-the-taxonomy-field-type/, the second solution I gave works in the admin. You’ll need to play with this since it’s a front end form and depending on what type of field it is, for checkboxes and miulti select fields you want to return an array but for single select and radio you’ll want to return just a single term ID.
I’m guessing here about what the $post_id
value will be
add_filter('acf/load_value/name=taxonomy_field_name', 'default_term_for_taxonomy_field_name', 10, 3);
function default_term_for_taxonomy_field_name($value, $post_id, $field) {
if ($value === false && get_post_status($post_id) == 'new_post') {
$value = array(3);
}
return $value;
}
I’m experiencing the very same issue, the wrapper width does not work everywhere.
In my case, the issue is related to Custom Taxonomies: I can see the “wrapper width” applied correctly on the Custom Taxonomy page, where they are listed, but not inside the single one when editing it.
Thanks for the support.
I’ve now got it working with the following code:
<?php
$terms = get_the_terms( get_the_ID(), 'product_brands' );
if( ! empty( $terms ) ) : ?>
<ul>
<?php foreach( $terms as $term ) : ?>
<li class="<?php echo $term->slug; ?>">
<img src="<?php the_field('brand_logo', $term); ?>" />
</li>
<?php endforeach; ?>
</ul>
<?php
endif;
?>
I had to change the taxonomy name from brands to product_brands because I was already using a brands taxonomy for another CPT. However, this wasn’t the cause of the images not displaying, the only thing that was missing before was wrapping the <?php the_field(‘brand_logo’, $term); ?> in an image tag, seems obvious now.
Are there any issues doing it this way?.
Is your field set to return the URL? or the object?
// ACF < 5.5.0
<img src="<?php the_field('image_field_name', $custom_term->taxonomy.'_'.$ $custom_term->term_id); ?>" alt="" class="img-responsive">
// ACF >= 5.5.0
<img src="<?php the_field('image_field_name', 'term_'.$custom_term->term_id); ?>" alt="" class="img-responsive">
See https://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/
If you are returning a image object/array instead of the url then see https://www.advancedcustomfields.com/resources/image/ for information on showing image fields.
This is not possible, or more accurately it is not built into ACF. You can get this result by adding your own custom JavaScript https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/. I don’t know exactly what you need to do, but the basics are that you need to add a change action to the taxonomy field, you should look for an example of getting values from Select2 fields. The see what the values are and then hide or show the fields you want to be conditional, you can do this by using that acf hidden-by-conditional-logic
class adding or removing this class from the fields you want to be conditional.
There are some solutions in this topic https://support.advancedcustomfields.com/forums/topic/conditional-logic-using-taxonomy-field/
This seems to give a solution http://idealienstudios.com/crazy-with-conditionals/
I am running ACF Pro 5.5.14, so I assume ACF should now be saving to term meta (?).
I participated in a previous thread in which it was said this would be supported from 5.5.
I just got back the id of the taxonomy. Which is actually what i need. I always thought it would give me back an array.
Now everything works!
Thanks for your help!
A taxonomy field will return an array of terms even if it can only have one term.
What is being output by your code?
You can try this to see what is being returned
$term = get_field('kategorie');
echo '<pre>'; print_r($term); echo '</pre>';
Hey John,
We’re using Advanced Custom Fields 4.4.11.
However, entering the code you supplied worked like a charm:
<?php
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
// the_field() echos the value and you do not need to include your own echo statement
the_field('game_publisher', $taxonomy.'_'.$term_id);
?>
Thank you!
Are you using ACF 4 or 5?
In either case you need to supply the correct post ID value. In ACF for this is "{$taonomy}_{$term_id}"
. In ACF 5 you can use the same value or you can use "term_{$term_id}"
In a tax archive template you can get the term ID like this
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
To get the field you should either use
// the_field() echos the value and you do not need to include your own echo statement
the_field('game_publisher', $taxonomy.'_'.$term_id);
or
echo get_field('game_publisher', $taxonomy.'_'.$term_id);
for more information see https://www.advancedcustomfields.com/resources/get_field/ Get a value from different objects
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.