Created
November 24, 2021 23:16
-
-
Save ahmadthedev/881d1aad5c248bcebd3b18a36f32002a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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