Co-Authors-Plus icon indicating copy to clipboard operation
Co-Authors-Plus copied to clipboard

Ajax suggest metabox shows 0 results frequent

Open dpacmittal opened this issue 11 years ago • 4 comments

In search_authors() function:

$args = array(
    'search' => $search,
    'get' => 'all',
    'number' => 10,
);
$args = apply_filters( 'coauthors_search_authors_get_terms_args', $args );
add_filter( 'terms_clauses', array( $this, 'filter_terms_clauses' ) );
$found_terms = get_terms( $this->coauthor_taxonomy, $args );
remove_filter( 'terms_clauses', array( $this, 'filter_terms_clauses' ) );

if ( empty( $found_terms ) )
    return array();
// Get the co-author objects
$found_users = array();
foreach( $found_terms as $found_term ) {
    $found_user = $this->get_coauthor_by( 'user_nicename', $found_term->slug );
    if ( !empty( $found_user ) )
        $found_users[$found_user->user_login] = $found_user;
}

This searches for only 10 terms. The array is then filtered using get_coauthor_by function. Sometimes this leaves the resultset to be empty, when it shouldn't be (because we only looked for 10 terms in the first place).

We should increase the 'number' to more sensible value, or find a better way (using SQL?) to get coauthors from the terms. Another solution would be to loop it until we have atleast X number of results.

dpacmittal avatar Nov 20 '14 13:11 dpacmittal

I am facing the same issue. Any update on this?

rohitkeshwani07 avatar Jan 18 '17 19:01 rohitkeshwani07

So, as of now a coauthor selected by get_terms() can be dropped if

  • it is in the ignored set (for ex. it already belongs to the post we are assigning coauthors to)
  • it does not have sufficient permissions.

The first case can be filtered out in get_terms() itself with the exclude argument, so that' good. The second case can't really be filtered out a priori, as far as I know.

One solution would be to select maybe 20 coauthors already excluding the $ignored ones, and then filtering for permissions. At this point I expect the resulting set to contain something, at least, but possibly more than 10 coauthors. We may then return at most 10 of them. What do you guys think @philipjohn ?

TheCrowned avatar May 30 '18 13:05 TheCrowned

Even with a limit of 20 we're likely to hit the same issue on a site with a large number of contributors.

What's stopping us from bumping the limit up to something like 100? What effect would that have on the query - would it make it too expensive? If so, could we be clever with caching to limit the impact?

philipjohn avatar Jun 05 '18 10:06 philipjohn

With #544, users who do not have the capability to be added as coauthors will not have a wp_term set up anymore at all, so this problem is likely to be at least 80% fixed. At that point, the limit will just be how many coauthors we are ignoring. For the search results to be empty, the post will have to have 10 coauthors already. If this happens often, we could bump the limit to 20 and we should be fine! Thoughts @philipjohn ? :)

TheCrowned avatar Jun 13 '18 15:06 TheCrowned