Skip to content

Instantly share code, notes, and snippets.

@laurelstreng
Last active May 13, 2020 15:11
Show Gist options
  • Save laurelstreng/f98db35d05be738761f70e19cbd71ff3 to your computer and use it in GitHub Desktop.
Save laurelstreng/f98db35d05be738761f70e19cbd71ff3 to your computer and use it in GitHub Desktop.
How to get Post ID by Meta Value
<?php
// Example: Query to show pages that have a meta_value that contains a string (not exact)
// https://rudrastyh.com/wordpress/meta_query.html
$args = array(
'post_type' => 'page',
'meta_query' => array(
array(
'value' => '[contact-form-7 id="13127" title="Alliance',
'compare' => 'LIKE'
)
)
);
$my_query = new WP_Query( $args );
if( $my_query->have_posts() ) {
while( $my_query->have_posts() ) {
$my_query->the_post();
// d(get_post());
}
}
wp_reset_postdata();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment