Good day to everyone
Let me quickly say that ACF is one of the most important and great things that ever happened to WP.
Now onward to my problem.
I have a custom taxonomy populated with a few categories. I have created some custom fields (a multiple select and a textfield) for these categories but i cant figure out how to show them.
For example i can populate the options of a select with the following query
$taxonomy = array( 'katigories-ekdoseon' );
$taxargs = array(
'orderby' => 'name',
'order' => 'ASC',
'fields' => 'all',
'parent' => 108,
'hierarchical' => true,
'child_of' => 0
);
$taxterms = get_terms($taxonomy, $taxargs);
… and then …
<?php foreach ($taxterms as $taxterm) { ?>
<option value=".<?php echo $taxterm->slug; ?>"
data-cf="">
<?php echo $taxterm->name; ?>
>
</option>
<?php } ?>
When i try to fetch the custom fields for each of my categories, it simply does not show them.
An example of what i tried is the following:
<?php foreach ($taxterms as $taxterm) { ?>
<option value=".<?php echo $taxterm->slug; ?>"
data-cf="<?php $custom_field = get_field('test', $taxterm ); ?>">
<?php echo $taxterm->name; ?>
</option>
<?php } ?>
or
<?php foreach ($taxterms as $taxterm) { ?>
<option value=".<?php echo $taxterm->slug; ?>"
<?php $cfmultipleselect = get_field('multiple_select'); ?>
<?php if( $cfmultipleselect ) : ?>
data-cf="<?php echo implode(', ', $cfmultipleselect); ?>"
<?php endif; ?>
>
<?php echo $taxterm->name; ?>
</option>
<?php } ?>
Am i not getting something?
Thank you for your time people
It should be working, sort of. The loop you are using looks right but some of the other stuff may be wrong.
On the text field, you’re not echoing the value
data-cf="<?php $custom_field = get_field('test', $taxterm ); ?>">
should be
data-cf="<?php echo get_field('test', $taxterm ); ?>">
or
data-cf="<?php the_field('test', $taxterm ); ?>">
The select field on the other hand might be what you have the return value set to. If you are returning the label or alue then it will be correct, but if you’re returning an array then the issue is that you’re trying to implode a nested array, which will not work.
Also, I don’t know what the “cf-data” attribute is. An attribute of an html element will not be shown on the page, unless you are looking at the html output, in which case you can ignore my ignorance π
You must be logged in to reply to this topic.
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βre excited to announce we've released Composer support for installing ACF PRO.
— Advanced Custom Fields (@wp_acf) January 31, 2023
π #ComposerPHP fans rejoice!
β¨ Please see the release post for all the details and full instructions. https://t.co/ebEfp61nlR
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.