Created
May 7, 2018 12:00
-
-
Save daler445/b664c353ddb9adf6e9bc0708245cddd8 to your computer and use it in GitHub Desktop.
get custom post type by custom post object field
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 | |
include("wp-load.php"); | |
$val_to_search = 2824; | |
$args = array( | |
'post_type' => 'projects', | |
'posts_per_page' => 5, | |
'meta_key' => 'field_name', // post object | |
'meta_value' => $val_to_search | |
); | |
$data = new WP_Query($args); | |
if ($data->have_posts()) { | |
while($data->have_posts()) { | |
$data->the_post(); | |
echo "<b>Title:</b> " . get_the_title() . "<br /><b>ID:</b> " . get_the_ID() . "<br />"; | |
print_r(get_field("field_name")); | |
echo "<br /><br /><hr>"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment