The cause was indeed something else not ACF related, but I’m very very busy at the moment 🙂 Will get back to this post in about a week!
… actually, strike that: I was too quick with drawing conclusions.
This has nothing to do with the Jesse Heap snippet of code.
I found that if I use ACF group and use code like this to display a sub item in that group:
<?php if( have_rows('site_header', 'option') ): ?>
<?php while( have_rows('site_header', 'option') ): the_row(); ?>
<?php if(get_sub_field('phone', 'option')) : ?>
<div id="phone">
<span class="hide-on-phone hide-on-tablet"><?php the_sub_field('phone_header', 'option') ?></span>
<a href="tel:<?php the_sub_field('phone_computer', 'option') ?>"><?php the_sub_field('phone', 'option') ?></a>
</div>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
… that this will not display on a search results page. A bug?
… never mind, I found the cause of the problem. I’ve used this script:
http://projects.jesseheap.com/all-projects/wordpress-plugin-tag-search-in-wordpress-23
which seems to interfere with ACF. Looking to find a workaround.
Hi Federico!
I was on a holiday so late reply here.
Can you be more specific, do you have example code?
Anyway, the code I used in my functions.php was:
/**
* Hooks the WP cpt_post_types filter
*
* @param array $post_types An array of post type names that the templates be used by
* @return array The array of post type names that the templates be used by
**/
function my_cpt_post_types( $post_types ) {
$post_types[] = 'beugel';
$post_types[] = 'kingweg';
$post_types[] = 'groep_8';
return $post_types;
}
add_filter( 'cpt_post_types', 'my_cpt_post_types' );
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', 'my_taxonomy_query', 10, 3);
OK, found out what went wrong. I hadn’t updated to PRO, so I could not get the field_XXXX etc from the field I wanted to sort on.
Oh my… nobody here to help me out? Am I overlooking something? Any help would be greatly appreciated 🙂
Tried all suggested solutions, nothing worked unfortunately.
For instance, one of the examples, this is the code I use in my function.php:
function my_acf_update_value( $value, $post_id, $field ) {
$mc_sort_id_FIELD_KEY = 'field_59711bd65b276'; // Set this to the field key of your field called "mc_sort_id".
$order = [];
foreach ( $repeater as $i => $row ) {
$order[ $i ] = $row[ $mc_sort_id_FIELD_KEY ];
}
array_multisort( $order, SORT_ASC, $value );
return $value;
}
add_filter( 'acf/update_value/name=datumprik', 'my_acf_update_value', 10, 3 );
And this is where I got the values “field_59711bd65b276” and “datumprik”):
So I want the backend to order ascending on the “datumprik” field. Am I missing something or is there something wrong?
Thanks John, I will try this out today!
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.