Closed tonyketcham closed 1 year ago
+1 I'm facing the same problem, I saw that each time that I press a key, It 's calling a ajax, I thing that a debounce can solve the problem
I think having a config option on the association
type, which constrains the search to only considering the specific field you declare (such as the post title) combined with debouncing could reduce or solve the problem
Hi, did you find anything for this issue? I'm facing the same thing, it only loads the first 20 items and then if I keep scrolling to see the rest of the items list, it crashes.
Hi @tonyketcham ,
Currently, we're using the s
parameter in the WP_Query
object, which would trigger the WP core search functionality.
If you'd like to override this you could try using our filter and override the arguments for the WP Query and then you could add a filter for the WP Query.
The filter is using the field name and field context and looks like this: carbon_fields_association_field_options_{field_name}_{context_type}_{post_type}
.
In most cases the {context_type}
would be simply post
, and the {post_type}
could be any post type that you would use the block for.
With this filter, you could also override the search field and you could search inside post_content
instead, or even in the post meta fields.
Here is an example of usage with the block field that you've used:
add_filter( 'carbon_fields_association_field_options_gnl_article_embed_post_post', function( $args ) {
if ( ! empty( $args['s'] ) ) {
$search_term = $args['s'];
unset( $args['s'] );
$args['search_by_title'] = $search_term;
add_filter( 'posts_where', 'gnl_posts_where', 10, 2 );
}
return $args;
} );
function gnl_posts_where( $where, $wp_query ) {
global $wpdb;
$search_by_title = $wp_query->get( 'search_by_title' );
if ( ! empty( $search_by_title ) ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( $wpdb->esc_like( $search_by_title ) ) . '%\'';
}
return $where;
}
More information is available in our documentation in Advanced > PHP Hooks > Association Field section. https://docs.carbonfields.net/learn/advanced-topics/php-hooks.html#association-field
Hi @Cariloha,
Currently, we're unable to reproduce your issue.
Please open a new issue and provide us with more information regarding your WP version, PHP version, Carbon Fields version, the used container, and fields.
Also, you could first try upgrading to our latest release and then re-check if the issue still exists.
Version
Expected Behavior
Searching for a custom post type returns entries with keyword matches in the title.
Working example with Video Block
Although our video custom post type often has body text in the entires, (much less content than the custom post type we're experiencing the issue with) the search works just fine
Actual Behavior
Using the
association
field to embed a standard custom post type (articles) inside other articles (of which there are 30-60k+ per site) causes the search feature to return unrelated/glitchy results 9 times out of 10. It will often loop forever between increasing the returned results to decreasing them, with none of the returned results being relevant to the search query. My guess is that the search field is perhaps trying to compare keywords to the body content of every article in the 30k+ entries, rather than just the titles? I could be wrong in that assumption.The search lags very intensely for articles, where the bulk of the time it returns segmented iterations of results, none of which have any relation to the query.
Undesired current article block search
However, while still quite slow for the articles...
This specific query was found to return some expected results As does the video block
Container definition
Video Block
Article Block
Steps to Reproduce the Problem
association
fieldComments
I'm looking for a way to have the search feature strictly compare to the
post
taxonomy (our articles) title content, and return relevant results. Could I perhaps specify something in the association query to compare the search query to ONLY the post title?