With the help of the meta_query attribute in the powerful WordPress WP_Query class, posts can be filtered that have certain values in their meta fields. If you have created a multi-line meta field (eg with the help of Advanced Custom Fields ) and only want to find posts that contain a certain value in this field separated by line breaks, the REGEX world of MySQL is recommended.
The following call finds all posts that have the value bar somewhere in a line in the foo field:
This ensures that no incorrect substrings are found and that line breaks work across platforms. Also important: The value of the value attribute must be in double quotation marks, otherwise WordPress will escape the backslashes (don't worry: Prettier takes this into account permanently). The same procedure can also be used for other purposes: For example, in the code above, "\ r \ n | \ r | \ n" is replaced by " ;" if the values are comma (instead of line) separated within a text field.