Look for string in posts and postmeta

I have a query that finds the usage of an attachment in any post.

$used_in_content = array();

foreach ( $attachment_urls as $attachment_url ) {
$content_query = new WP_Query( array(
‘s’ => $attachment_url,
‘post_type’ => ‘any’,
‘fields’ => ‘ids’,
‘no_found_rows’ => true,
‘posts_per_page’ => -1,
) );

$used_in_content = array_merge( $used_in_content, $content_query->posts );
}

However, the string can also be in the posts meta values. How can I change this query, so that it also looks in the post meta values? I tried out different things, but they didn’t work. I’m really in the dark here, as I am not really familiar with how these queries work.

Read more here:: Look for string in posts and postmeta

Leave a Reply

Your email address will not be published. Required fields are marked *