Hi rhcarlosweb, unfortunately there wasn’t a solution to this. I did get an official response from ACF confirming this, but I can’t seem to find it.
Since the client had a limited number of categories, I just selected each one of them in the “Filter by Taxonomy” field. Definitely not ideal, but it works for now.
Thanks again for helping out, John. I built a workaround by adding various radio buttons to the UX. Not ideal but it gets the job done.
Sadly the same result. FYI, I have the code at the bottom of my functions.php file.
John, thank you so much for the quick response! They are similar but not the same.
field_5c7ea3fd1ff26
field_5c8fe92190fd6
I am trying to do simple validation on a text field. If no value, then require a different field. It is not working for me; it’s choking and preventing form submission whether or not there is a value in the text field. Any thoughts on what I’m missing?
// conditionally require video field IF playlist ID field is blank
add_filter('acf/validate_value/key=field_5c7ea3fd1ff26', 'acf_validate_video', 10, 4);
function acf_validate_video( $valid, $value, $field, $input ) {
// bail early if value is already invalid
if( !$valid ) { return $valid; }
//$playlistID = 'test';
$playlistID = $_POST['acf']['field_5c8fe92190fd6'];
if ( $playlistID == '' ) {
if (!$value) {
$valid = __('You must select a video if no Playlist ID is defined.');
}
}
return $valid;
}
more context:
With the relationship field, I can only choose the categories one by one, rather than just choose “categories,” as you can with a Taxonomy custom field. So, as categories change, I’d have to adjust each relationship field, and there are MANY.
Taxonomy custom field = filter by taxonomy TYPE
Relationship custom field = filter by taxonomy TERM
Need the relationship custom field to filter by ALL categories (and ONLY categories, not tags) without selecting each one manually.
Apologies if this is a duplicate reply. The system hasn’t accepted previous submits.
__
I instead chose to run the __search_by_title_only function only when a user is logged in, which satisfies my requirement.
Here’s the exact code I used:
function __search_by_title_only( $search, $wp_query )
{
global $wpdb;
$q = $wp_query->query_vars;
$n = ! empty( $q[‘exact’] ) ? ” : ‘%’;
$search =
$searchand = ”;
foreach ( (array) $q[‘search_terms’] as $term ) {
$term = esc_sql( like_escape( $term ) );
$search .= “{$searchand}($wpdb->posts.post_title LIKE ‘{$n}{$term}{$n}’)”;
$searchand = ‘ AND ‘;
}
if ( ! empty( $search ) ) {
$search = ” AND ({$search}) “;
}
return $search;
}
// call this function ONLY if user is logged in (e.g. admin, editor)
if ( is_user_logged_in() ) {
add_filter(‘posts_search’, ‘__search_by_title_only’, 500, 2);
}
FYI:
I omitted the “&” from the 2nd parameter because it was throwing errors sitewide: “Parameter 2 to __search_by_title_only( ) expected to be a reference”
Produced errors:
function __search_by_title_only( $search, &$wp_query )
Working:
function __search_by_title_only( $search, $wp_query )
Hi John, thanks for your reply. I misspoke. It’s not searching meta but rather post_content, and I ONLY want it to search post_title.
Can I alter the query to only apply to ACF cases (acf/fields/post_object/query)? I certainly don’t want to alter it sitewide.
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.