Skip to content

Instantly share code, notes, and snippets.

@ahmadthedev
Created November 24, 2021 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmadthedev/881d1aad5c248bcebd3b18a36f32002a to your computer and use it in GitHub Desktop.
Save ahmadthedev/881d1aad5c248bcebd3b18a36f32002a to your computer and use it in GitHub Desktop.
<?php
if (!function_exists('get_post_ids_by_meta_key_and_value')) {
function get_post_ids_by_meta_key_and_value($key, $value) {
global $wpdb;
$meta = $wpdb->get_results("SELECT post_id FROM `".$wpdb->postmeta."` WHERE meta_key='".$wpdb->escape($key)."' AND meta_value='".$wpdb->escape($value)."'");
$post_ids = [];
foreach( $meta as $m ) {
$post_ids[] = $m->post_id;
}
return $post_ids;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment