Last active
May 26, 2022 20:04
-
-
Save maheshwaghmare/99a9f07e1b6372fc6d31c57eefdc3234 to your computer and use it in GitHub Desktop.
Get all post IDs which have meta key `location` and meta value `Pune`.
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 | |
| /** | |
| * Get Post By Meta | |
| * | |
| * Get all post IDs which have meta key `location` and meta value `Pune` | |
| * | |
| * @todo Change the `prefix_` and with your own unique prefix. | |
| * | |
| * @since 1.0.0 | |
| */ | |
| if( ! function_exists( 'prefix_get_post_by_meta' ) ) : | |
| function prefix_get_post_by_meta() { | |
| global $wpdb; | |
| // Get all IDs | |
| $post_ids = $wpdb->get_results( | |
| 'SELECT `post_id` FROM `' . $wpdb->postmeta . '` | |
| WHERE `meta_key` = \'location\' | |
| AND `meta_value` = \'Pune\' | |
| ;' | |
| ); | |
| return $post_ids; | |
| } | |
| // add_action( 'admin_head', 'prefix_get_post_by_meta' ); | |
| endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment