Skip to content

Instantly share code, notes, and snippets.

@harisrozak
Last active April 26, 2019 06:44
Show Gist options
  • Save harisrozak/60b553e8b29f866f493c4e6289029b34 to your computer and use it in GitHub Desktop.
Save harisrozak/60b553e8b29f866f493c4e6289029b34 to your computer and use it in GitHub Desktop.
WordPress::Wp_Query with field ids
<?php
$args = array(
'post_type' => 'custom-post',
'posts_per_page' => 10,
'post_status' => 'publish',
'author' => 1,
'fields' => 'ids',
'tax_query' => array(
array(
'taxonomy' => 'custom-tax',
'field' => 'name',
'terms' => 'new-term',
),
),
);
$the_query = new WP_Query($args);
$ids = array();
/* result post ids */
if($the_query->have_posts()) {
$ids = $the_query->posts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment