Assuming that this meta is for the post type “post” you could create a loop in two ways, get_posts
or WP_Query
.
I also prefer the meta_query
property over the meta_value
and meta_key
, because it adds the option to add more meta queries quicker as the array already exists.
The get_posts
method
$posts = get_posts([
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => [
[
'key' => 'publisher',
'value' => 'IBM',
]
]
]);
foreach ($posts as $post) {
// your code here
}
The WP_Query
method
$posts = new WP_Query([
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => [
[
'key' => 'publisher',
'value' => 'IBM',
]
]
]);
if ($posts->have_posts()) {
while ($posts->have_posts()) {
the_post();
// your code here
}
}
The best resource for understanding how this works is the WP_Query documentation