I try echo on any page (I mean page on my site) all post IDs what I have in my taxonomy.
I found this:
get a list of posts from Custom Taxonomy
But I could not handle with it.
I want to echo all currently published post IDs what the taxonomy contains.
Name taxonomy = ‘agency’
Post type=”job_listing”
<input value="<?php echo $idsTaxonomy"?>
And I would see output example:
420, 16, 5
Somone could help me? Thank you for help.
1 Answer
Just some code to get started. This will get you all the IDs for job_listings that are assigned to term 4 in your taxonomy.
<?php
$posts = get_posts( array(
'posts_per_page' => -1,
'fields' => 'ids',
'post_type' => 'job_listing',
'tax_query' => array(
array(
'taxonomy' => 'agency',
'field' => 'term_id',
'terms' => 4
)
)
) );
echo implode( ', ', $posts );
?>