manifest / integrations / meom-user-query
MEOM user query
MEOM user query for REST API calls.
★ 1stars
270composer installs
0.1.0latest · 4 years ago
Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/meom/meom-user-query/archive/refs/heads/main.zipOn Packagist as meom/meom-user-query:
composer require meom/meom-user-queryNo built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.
This plugin is similar as WP_Query Route To REST API but for WP User Query.
MEOM user query adds new route /wp-json/user_query/args/ to REST API. You can query users with WP_User_Query args.
Install
Use Composer to install the package.
composer require meom/meom-user-query
Or if living on the edge:
composer require meom/meom-user-query:dev-main
Return HTML from request
Sometimes it's usefull to return HTML from request and use PHP templates for generating markup.
Disable REST query.
add_filter( 'wp_user_query_to_rest_api_allow_query', '__return_false' );
Set default data
/**
* 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 the query to return HTML.
/**
* 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 );Releases
1 release.
Tag
Published
0.1.0
latest
Mar 9, 2022 4 years ago
These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.