You’d want something like:
if ( have_rows('people', 'option') ) while ( have_rows('people', 'option') ) {
the_row();
if ( in_array( get_the_ID(), array_merge( get_sub_field('relationship_field_for_posts'), get_sub_field('relationship_field_for_pages') ) ) {
the_sub_field('name');
echo '<br>';
the_sub_field('age');
}
}
This code would cycle through all items in the people repeater, then check to see if the current ID is in either the relationship field for posts, or the relationship field for pages. If found in one of those fields, it will print out the info.
That behavior seems inconsistent; posts search titles and content, but terms search titles and slugs. I’ve filed a ticket with core to make this more consistent. I’ll post if anything changes. Thanks a lot, man.
Yes, the id that gets pulled in as a parenthetical is the slug of a taxonomy term. But the parenthetical on the post object is the post_name of the post.
Here are screenshots of the sub-fields. I’m adding a parenthetical to the search results for the taxonomy and post object fields. In the taxonomy field, you can see the underlining indicating that the parenthetical was included in the search term. This is not happening for post objects.
Thanks for looking. That’s pretty much my conclusion when I was tracing through it. I was hoping that maybe I missed something or that such functionality could be added in a future version of ACF, where you could manipulate a field’s query via Javascript. The relationship field does something similar, but it’s kind of bulky for a repeater.
It’s loading posts as I scroll. I believe it’s the enhanced ui, it’s using select2 to build a searchable select.
If type_metier
is a taxonomy field set to display as checkboxes,
$terms = get_field('type_metier');
if ( $terms ) {
foreach ( $terms as $t) {
$term = get_term( $t, 'taxonomy' );
echo $term->name . '<br>';
}
}
If you’re trying to just print values from checkboxes, it would be something like,
$values = get_field('type_metier');
if ( $values) {
foreach ( $values as $v) {
echo $v . '<br>';
}
}
When editing that field, set “Allow Null?” to yes. Then you’ll have an “x” in the ui that will allow you to blank this field.
You can get the username by using something like:
$user_field = get_field('user_field_name');
if ( $user_field ) {
$user_info = get_userdata( $user_field['ID'] );
echo 'Username: ' . $user_info->user_login;
}
Thanks! That filter works great for taxonomies, but I noticed a little inconsistency between the result filter for taxonomy fields and the one for post object fields. When I’m searching within select2, whatever I’ve appended to the result via this filter is searched and included. But with post objects the search is done before the result filter is called.
So if I had “Some entity (P012)” in both a taxonomy field and post object field–the parenthetical would be added by the result filter–searching for “P012” would only return this result in the taxonomy field, not in the post object field. Is this expected?
Sweet, I linked to this post from there so it’s cross-referenced.
Can this type of filter please be added to the taxonomy and post object fields as well?
I’ve done some more testing and it looks like the issue was the Post Type Switcher plugin (v1.3). When I have that deactivated the field groups save correctly.
The latest news regarding ACF5 tends to appear on Twitter before anywhere else, I sometimes check Elliot’s feed to keep abreast of things like this.
Thanks, man! That’s great, glad to help.
I’m on WordPress 3.6.1 and ACF 4.2.2 and I’m experiencing this issue with a custom post type. The post type is not public, and is set to only support title and revisions. Changes to the title cause new revisions to be created, but changing values of ACF fields do not.
I reverted to ACF 4.2.0 and am not experiencing this issue in that version.
I’m having the same problem with WP 3.6, ACF 4.2.1 and Flexible Content Field 1.0.2. I’ve tried creating a new flexible field with a relationship field inside it. After putting error_log(var_export($value, true)); into line 891 of core/fields/relationship.php I can see nothing in my error log wrong with the values that are being passed through the function — but no values are being saved.
+1! This is exactly the kind of feature I requested on the old forum. Such a front-end filter would be immensely useful.
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.