PHP code example of meom / meom-user-query

1. Go to this page and download the library: Download meom/meom-user-query library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

meom / meom-user-query example snippets


add_filter( 'wp_user_query_to_rest_api_allow_query', '__return_false' );

/**
 * Modify default data.
 *
 * @param array $data Default data.
 * @return array Modified default data.
 */
function prefix_default_data( $data ) {
    $data = array(
        'html'     => false,
        'messages' => array(
            'empty' => esc_html__( 'No results found.', 'textdomain' ),
        ),
    );

    return $data;
}
add_filter( 'wp_user_query_to_rest_api_default_data', 'prefix_default_data' );

/**
 * Modify WP User Query data to return HTML.
 *
 * @param array  $data Data inside loop.
 * @param object $user_query WP User Query.
 * @param array  $args Arguments.
 * @return array Modified data.
 */
function prefix_modify_user_data( $data, $user_query, $args ) {
    if ( ! empty( $user_query->get_results() ) ) {
        $html = '';

        ob_start();

        foreach ( $user_query->get_results() as $user ) {
            // Change this to your needs.
            // In this example we pass user ID to the template and do the markup in there.
            get_template_part( 'partials/user/user-item', null, [ 'author_id' => $user->ID ] );
        }

        $html .= ob_get_clean();

        $data['html'] = $html;

        wp_reset_postdata();
    }

    return $data;
}
add_filter( 'wp_user_query_to_rest_api_after_loop_data', 'prefix_modify_user_data', 10, 3 );