How using the Meta Box plugin, to filter posts by the value of a post type field?

I’m not familiar with the Meta Box plugin or it’s capabilities (and please note that third-party products are considered off-topic here!) – but regarding the question in the scope of core WordPress alone…

For clarity’s sake, I envision the lessons_teacher meta-value to look similar to

[['post_name' => 'john_smith'], ['post_name' => 'jane_doe']]

SQL – and by extension WordPress’s meta-query functionality – is not designed to be used against complex serialized data; SQL has no concept of PHP serialization – it simply treats complex serialized data as a string. While it is possible to work around this limitation to an extent, it should be noted that such a work-around comes with performance implications and a degree of fallibility – the mechanism is not robust and may yield the wrong result depending on the content of the serialized value.

The best solution is to store the associated teachers as singular post names in multiple meta data fields with the same name, or otherwise break the complex serialized data down into multiple non-serialized fields.

That in mind, the work-around consists of querying against the value which is actually stored in the database rather than it’s unserialized PHP representation. The array of associative arrays above would be stored as the string:

a:2:{i:0;a:1:{s:9:"post_name";s:10:"john_smith";}i:1;a:1:{s:9:"post_name";s:8:"jane_doe";}}

In effect, you would want to query for posts which have a meta value for the key lessons_teacher containing the sequence s:9:"post_name";s:<post_name length>:"<post_name>";

$teacher_post_name="john-smith";
$teacher_meta_val  = sprintf(
    's:9:"post_name";s:%d:"%s";',
    strlen($teacher_post_name),
    $teacher_post_name
);
$query_args        = [
  'post_type'      => 'lessons',
  'posts_per_page' => -1
  'meta_key'       => 'lessons_teacher',
  'meta_value'     => $teacher_meta_val,
  'meta_compare'   => 'LIKE',
];

Notes:

  • You could also use a REGEXP comparison operator here – but either one has serious performance implications for the query.
  • I’ve omitted your orderby meta-value argument because it most certainly will not achieve what you’d like – it would order results by the serialized string.
  • You could simplify the meta_value to just $teacher_post_name – but that might risk additional false-positives if a teacher post name (or something with the same characters) appears elsewhere in the complex serialized data.

Ultimately, I would not ship something containing this code – the additional overhead and risk of failure is too great when simpler and more efficient alternatives are available.

By contrast, if you were to store each associated teacher’s post_name by itself in it’s own lessons_teacher meta-field, the query would would be a simple

$query_args        = [
  'post_type'      => 'lessons',
  'posts_per_page' => -1
  'meta_key'       => 'lessons_teacher',
  'meta_value'     => $teacher_post_name,
];

with substantially greater performance and virtually no risk of false-positives.