Last active
May 13, 2020 15:11
-
-
Save laurelstreng/f98db35d05be738761f70e19cbd71ff3 to your computer and use it in GitHub Desktop.
How to get Post ID by Meta Value
This file contains 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 | |
// 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