Forums Forums Search & Filter Pro Author field too big to load

Tagged: ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Anonymous
    #222767

    The Problem: I need to load an author dropdown on the filter with just the Editors

    I have a Filter for my site, with several fields, one of them is Author, but the website has more than 15.000 users registered and get a timeout error every time the field is enabled.

    I’ve tried this to re write the author field with a more manageable amount of users (only the Editors) but with no luck the idea was to remove all content from _sf_author and replace it with the editors

    `
    function filter_authors($input_object, $sfid)
    {
    if (($input_object[‘name’] != ‘_sf_author’) || ($input_object[‘type’] != ‘select’)) {
    return $input_object;
    }

    unset($input_object[‘options’]);
    $input_object[‘options’] = array();

    // Generate first array option (default)
    $first_option = new StdClass();
    $first_option->value = ”;
    $first_option->label = ‘All Authors’;

    //attributes
    $first_option->attributes = array(
    ‘title’ => ‘All Authors’,
    );

    array_push($input_object[‘options’], $first_option);

    //change classes & attributes of the field
    $input_object[‘attributes’][‘class’] = ‘user_filter’;
    $input_object[‘attributes’][‘title’] = ‘Authors’;

    //add/override prefix & postfix to the field
    $input_object[‘prefix’] = “Filter by Author”;

    //Check if options variable exists
    if (!isset($input_object[‘options’])) {
    return $input_object;
    }

    //Create new users array
    $args = array(
    ‘role’ => ‘editor’,
    ‘order’ => ‘ASC’,
    ‘orderby’ => ‘display_name’,
    );

    // Create the WP_User_Query object
    $wp_user_query = new WP_User_Query($args);
    $authors = $wp_user_query->get_results();
    foreach ($authors as $author) {
    // get all the user’s data
    $author_info = get_userdata($author->ID);
    //create new options with user values
    $new_option = new StdClass();
    $new_option->value = $author_info->user_login;
    $new_option->label = $author_info->first_name . ‘ ‘ . $author_info->last_name;

    //attributes
    $new_option->attributes = array(
    ‘title’ => $author_info->user_login,
    );
    array_push($input_object[‘options’], $new_option);
    }
    return $input_object;
    }
    // add_filter(‘sf_input_object_pre’, ‘filter_authors’, 10, 2);
    `
    Using this approach i change a meta field and filled it with the Editors data, but then the post request was send as _sfm_editors and not _sf_author and i couldn’t find a way to replace this request for the one i needed.

    Also tried building my own query accessing the search data and using the hook sf_results_url to change the url, but i cannot change the search query with it.

    I’m running out of ideas, appreciate your time to check my issue and any new ideas on how to solve it.

    Trevor
    #222783

    I am sorry, but your license appears to have expired recently, did you renew it? If not, you will first need to renew the license to receive updates or support.

    However, you are sort of correct. The author field, for a site with a large number of users, is impractical. The load on the server will be way too high for every page load and search.

    The only way I can think to do this is to create a Custom Post Type for the Editors (Article Authors), and use ACF and its Post Type field object and for each post then select the author. There may be a way to programmatically retrospectively complete this field, but you may need to ask the team at ACF about that (Elliot at ACF will know a way).

    The reason for doing it this way, is you can add Authors by creating a Post in that CPT, and you can edit those posts, where the Title would be the Author name in the format you want to allow sorting; so it might be SURNAME, FORENAME type format.

Viewing 2 posts - 1 through 2 (of 2 total)