Sadly, no luck again.
Sadly, your code snippet doesn’t work.
Btw, it’s this plugin: https://wordpress.org/plugins/insert-php-code-snippet/
But I don’t expect anything in this direction. Maybe I will try to integrate the code directly into the theme.
And I really need to buy you a coffee. Any chance?
Then I think it’s the missing post ID.
The query filter/function is located in my child theme’s functions.php.
The code snippet is inserted directly into the post via shortcode by a plugin that enables php code through a shortcode. It’s not in a template file.
Yes, output is simply:
bool(false)
Not sure what to do with that though. Some boxes in the acf field are certainly checked.
Btw, regardless of this problem, you already deserved your coffee. Any way to send you the financial means for that? 😉
Ok, that’s weird. Of course, I want to show the marked terms on my frontend. I used the code ‘Basic display (multiple terms)’ (https://www.advancedcustomfields.com/resources/taxonomy/) as it’s a checkbox, but no output is produced. It seems like the array is empty.
My code:
<p>Hier sollten die Tags stehen:
<?php $ttterms = get_field('ti_tag_test');
if( $ttterms ): ?>
<?php foreach( $ttterms as $ttterm ): ?>
<?php echo $ttterm->name; ?>
<?php endforeach; ?>
<?php endif; ?>
</p>
– I tried it with term object and term id.
– …with $ttterm->name and $ttterm alone.
– At least one term is checked.
What am I missing?
Haha, there’s absolutely no reason for you to apologise. Thanks a lot for your continuous help, much appreciated! It’s working now.
function my_taxonomy_wp_list_categories( $args, $field ) {
// modify args
$args['orderby'] = 'count';
$args['order'] = 'ASC';
$args['include'] = '589,186'; // list of terms to include
// return
return $args;
}
add_filter('acf/fields/taxonomy/wp_list_categories/name=ti_tag_test', 'my_taxonomy_wp_list_categories', 10, 2);
Yes, it’s in the functions.php of my (child) theme.
Ok, I added those line in wp-config.php:
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );
// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
I can see it’s working because the debug.log was created and is being filled with error messages.
I added your error_log snippet directly under the function start:
function my_taxonomy_query( $args, $field, $post_id ) {
error_log('My Filter Was Called');
// modify args
$args['orderby'] = 'count';
$args['order'] = 'ASC';
$args['include'] = '589,186'; // list of terms to include
// return
return $args;
}
add_filter('acf/fields/taxonomy/query/name=ti_tag_test', 'my_taxonomy_query', 10, 3 );
Not sure about this position though.
So far, nothing like ‘My Filter Was Called’ in the error_log.
Thanks a lot.
I got the meaning of $args already from your previous post.
Currently it’s a top level field ‘taxonomy’, but in the end it’s supposed to be in a field group. I’ll attach some screenshots, German language though.
NULL-Werte zulassen? = empty values allowed
Einträge laden = load entries
I’m on a dead-end here. I noticed from another coding issue that I should define the variables written in the function ($args, $field, $post_id). Post ID is clear what to do with it, but I’m not sure if and with what I should define $args and $fields. I have no idea what $fields relates to at all.
$post_id = get_the_ID();
function my_taxonomy_query( $args, $field, $post_id ) {
// modify args
$args['orderby'] = 'count';
$args['order'] = 'ASC';
$args['include'] = '589,186'; // list of terms to include
// return
return $args;
}
add_filter('acf/fields/taxonomy/query/name=ti_tag_test', 'my_taxonomy_query', 10, 3 );
Not really sure what I can still change to make it work. For now, I have the following in my theme’s functions.php:
function my_taxonomy_query( $args, $field, $post_id ) {
// modify args
$args['orderby'] = 'count';
$args['order'] = 'ASC';
$args['include'] = '589,186'; // list of terms to include
// return
return $args;
}
add_filter('acf/fields/taxonomy/query/name=ti_tag_test', 'my_taxonomy_query', 10, 3 );
As far as I understand, the args value alters the get_terms function. I already defined which acf field I like to alter (add_filter, last row) and which tags to include with $args[‘include’]. It still shows all the tag terms though.
Thanks a lot for your additional informations, much appreciated. I will look into it tomorrow, it’s late here.
What I want to achieve is to show only certain tags that I’m gonna choose. Basically manually enter the tag IDs, we talk about 5-10 tags, not really a lot.
Hello John,
thanks for your link!
As a PHP beginner, I tried to use the code mentioned in the link in my theme’s function.php like this:
function my_taxonomy_query( $args, $field, $post_id ) {
// modify args
$args['orderby'] = 'count';
$args['order'] = 'ASC';
// return
return $args;
}
add_filter('acf/fields/taxonomy/query/name={$ti_tag_test}', 'my_taxonomy_query', 10, 3);
At least I assume it’s for the theme’s functions.php. I also assume that the numbers 10 and 3 are for the tag IDs? I tried every variation for the name= – with and without {} and $, but it always shows every tag available in the post editor. Or is it not something so easy to implement?
Yep, newbie here, sorry!
This is what I was looking for, found the corresponding snippet after long google sessions:
<?php
$linklist = array();
$links = get_field('ti_links');
if($links) {
foreach($links as $link) {
$linklist[] = '<a href="' . $link['url'] . '">' . $link['linktext'] . '</a>' . ' (' . $link['linksprache'] . ')';
}
echo implode(" | ", $linklist);
}
?>
I just didn’t know how to apply the implode, that was all. Still not sure why this magic works, but it works.
Ok, I’m pretty stucked. I’ll explain one more time what I want to achieve.
I want to build a list of links in one line with a separator like this:
“Links: Link1 | Link2 | Link3 | LinkX…”
I have a repeater field called ti_links with three subfields url, linktext and linksprache.
For each link, I want to echo this:
<a href="$url">$linktext</a> ($linksprache)
I’ve built a new code snippet with the check have_rows and a while loop, but I’m to embarrassed to show it here. At least it doesn’t produce errors but simply prints the values, nothing else. What I don’t get is how to put the subfields into an array and implode it for the output with separator.
Hello James,
thanks for your reply.
It’s not about debugging, the code snippet already works. I just don’t get how to achieve the output I mentioned as the aim – it’s more a styling problem with the separators. I googled a lot but for some reason, I don’t get the hang of it. I was hoping for some input from an experienced coder, I’m not even sure if my approach with foreach makes sense here.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.