Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search_authors() function doesn't return all results, if there are more than 10 results #1057

Open
maxledoux opened this issue Sep 6, 2024 · 0 comments

Comments

@maxledoux
Copy link

When you have a combined number of more than 10 WP Users + Guest Authors that return for the same search string, not all of the results are displayed for the user to choose from. (I.E. 9 WP users and 4 Guest Authors all with "Max" somewhere in the name)

The fix is:

add_filter( 'coauthors_search_authors_get_terms_args', 'how_coauthors_update_term_args', 10, 1 );
function how_coauthors_update_term_args( $args ) {
	$args['number'] = 0;
	return $args;
}

Which modifies the $args used by get_terms() here:

$found_terms = get_terms( $this->coauthor_taxonomy, $args );

So my question is, why are we specifying 'number' => 10, in the $args in the first place? And if there's no reason, then can we remove that? If there is a reason, can we nevertheless have all results returned as expected?

How to reproduce:
Create 6 WP users (editor role) all with first name "max"
Create 5 Guest Authors all with the first name "max"

Either use the UI (search in the Authors metabox) or use the endpoint: /wp-json/coauthors/v1/search/?max

However, you need to make the endpoint public first with:

function make_coauthors_search_route_public( $endpoints ) {
    if ( isset( $endpoints['/coauthors/v1/search'] ) ) {
        // Set the permission callback to always return true, making the endpoint public
        $endpoints['/coauthors/v1/search'][0]['permission_callback'] = '__return_true';
    }
    return $endpoints;
}
add_filter( 'rest_endpoints', 'make_coauthors_search_route_public' );

Either way, you should observe that not all 11 results are displayed. At least that's what I saw on multiple sites.

@maxledoux maxledoux changed the title Search Author metabox doesn't return all results Search Author author doesn't return all results, if there are more than 10 results Sep 6, 2024
@maxledoux maxledoux changed the title Search Author author doesn't return all results, if there are more than 10 results search_authors() function doesn't return all results, if there are more than 10 results Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant