How To Write An Inner Join With WP Query

Ok so the way I was able to just show English properties on the user admin page was with this posts_request hook:

add_filter('posts_request', function($sql, $query) {
  $is_user_edit_page = (
    isset($_SERVER['HTTP_REFERER']) &&
    strpos($_SERVER['HTTP_REFERER'], 'user-edit') !== false
  );

  $is_property_sql  = (strpos($sql, 'property') !== false);

  if ($is_user_edit_page && $is_property_sql) {
    $sql = str_replace("'sp'", "'en'", $sql);
  }

  return $sql;
}, 10, 2);

In this hook I make sure it only runs on the user-edit page and that the sql it’s changing relates to the properties. If all those cases are true, then I just replace the Spanish language code with the English one. And as a result, the SQL used to query the properties is forced to only query for English ones.

Thank you @Howdy_McGee for your comments on my question.

Leave a Comment