Skip to content

Instantly share code, notes, and snippets.

@daler445
Created May 7, 2018 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daler445/b664c353ddb9adf6e9bc0708245cddd8 to your computer and use it in GitHub Desktop.
Save daler445/b664c353ddb9adf6e9bc0708245cddd8 to your computer and use it in GitHub Desktop.
get custom post type by custom post object field
<?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