Over 2000 total News posts which is how I found this issue in the first place b/c I needed to be able to search on them rather than scroll through =P
That’s really strange. I added multiple post_types and changed to ‘all’ to test and it seems to be querying / grouping correctly.
You could try adding debug information into the method
function acf_get_grouped_posts( $args ) {
beginning on line 1547 in api/api-helpers.php
The issue for me was the
$posts = get_posts( $args );
call on line 1583 was not using the “s” arg correctly. I debugged it by dumping out the $args var and trial / error.
Yep, I’m filtering on a specific post_type, but only 1, not multiple post_types.
functions.php is where you would add it.
This solution is for a Post Object type specifically. If your field is a page_link you’d want to change the filter to
add_filter( 'acf/fields/page_link/query', 'acf_post_object_custom_query', 10, 3 );
I think I see the issue.
One line 1558 of api/api-helpers.php it is sorting the results using
'orderby' => 'menu_order title',
'order' => 'ASC',
For some reason, even though posts_per_page is set to 20, this was not respecting the ‘s’ query arg and returning 20 posts ordered alphabetically. The solution I found was to add a filter on ‘acf/fields/post_object/query’ and set the ‘orderby’ arg to null. This will override the default ‘menu_order title’ argument, and worked for me.
function acf_post_object_custom_query( $args, $field, $post_id )
{
$args['orderby'] = null;
return $args;
}
add_filter( 'acf/fields/post_object/query', 'acf_post_object_custom_query', 10, 3 );
These were my results searching for ‘traffic’.
Before:
After:
If there is a better solution, please post it.
Since this was only setting it to null and not actually deleting the row I wanted a better solution. I came up with this which essentially gets the position of the field you want and moves every row after it back one and then removes the last row of the repeater thus completely deleting that value.
https://gist.github.com/aaronjheinen/53ff4a44362927711d37
Don’t mind me.
Answer was found in the docs.
http://www.advancedcustomfields.com/resources/querying-relationship-fields/
This certainly can work but I’d like to keep the content area as-is for excerpt functionality. I did find a solution but it looks like it searches all post_meta, so it’s not something that can specifically be set.
I would like to see a “Searchable” Boolean added to field types.
// Search on custom fields
function custom_search_join ($join){
global $pagenow, $wpdb;
$types = ['course'];
// I want the filter only when performing a search on edit page of Custom Post Type in $types array
if ( is_admin() && $pagenow=='edit.php' && in_array( $_GET['post_type'], $types ) && isset( $_GET['s'] ) ) {
$join .='LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
return $join;
}
add_filter('posts_join', 'custom_search_join' );
function custom_search_where( $where ){
global $pagenow, $wpdb;
$types = ['course'];
// I want the filter only when performing a search on edit page of Custom Post Type in $types array
if ( is_admin() && $pagenow=='edit.php' && in_array( $_GET['post_type'], $types ) && isset( $_GET['s'] ) ) {
$where = preg_replace(
"/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
"(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
}
return $where;
}
add_filter( 'posts_where', 'custom_search_where' );
function custom_search_distinct( $where ){
global $pagenow, $wpdb;
$types = ['course'];
if ( is_admin() && $pagenow=='edit.php' && in_array( $_GET['post_type'], $types ) && isset( $_GET['s'] ) ) {
return "DISTINCT";
}
return $where;
}
add_filter( 'posts_distinct', 'custom_search_distinct' );
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 hard at work on ACF 6.1, and Beta 1 is now available 🚀
— Advanced Custom Fields (@wp_acf) March 16, 2023
This release includes custom post type and taxonomy registration, an improved experience when selecting field types, PHP 8.1 and 8.2 compatibility, and more!
Let’s take a look 🧵https://t.co/Y0WcAT11l4
© 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.