Is there a way of merging get_users() and and WP_Query() into one query so I can paginate the results? I have two entities; users and companies. Both can be members but users are users and company is a custom post. I would like to merge the query together so I can control them at once i.e. pagination.

$args = array(
  'role'    => 'member',
  'orderby' => 'user_nicename',
  'order'   => 'ASC',
  'meta_query' => array(
      'key'     => 'category',
      'value'   => $category->term_id,
      'compare' => 'LIKE',

$users = get_users( $args );

$params = [
  'post_type' => 'member_company',
  'paged' => get_query_var('paged') ?: 1,
  'member_category' => $category->slug,
  'posts_per_page' => 5

$query = new WP_Query($params);
  • Very unlikely, but if it was possible, I doubt it would be faster, some things just take multiple steps to do, muddying them by merging them isn't always an improvement – Tom J Nowell Sep 11 '18 at 17:33
  • Performance wasn't really my worry to be honest. – Abdul Sadik Yalcin Sep 13 '18 at 8:53
  • Re-reading your question I see your actual issue is how to implement pagination, and that merging the two queries is simply a proposed solution. Which are you trying to paginate? Or are you trying to list both users and posts in the same archive? If so, I don't think that's feasible. Perhaps you can create a CPT automatically via hooks that you can query for – Tom J Nowell Sep 13 '18 at 15:59
  • Well it's not just pagination but listing them together. It's quite confusing as there is a 3 way relation. There are categories (custom taxonomy). A user and a CPT can be within that category. Unfortunately, my old colleague did not create members as a CPT but just built it on top of default WP users. So I need a way of displaying both on the same page and paginate them. Both have their own template part as well. – Abdul Sadik Yalcin Sep 13 '18 at 16:51
  • You can't have both users and posts in the same custom taxonomy, WP has no way to know if you meant the post with ID 5 or the user with ID 5. Otherwise no, you can't merge the queries together like this – Tom J Nowell Sep 13 '18 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.