Skip to content

Instantly share code, notes, and snippets.

@amirhp-com
Last active July 27, 2020 08:39
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 amirhp-com/6094b1a97e77d9e77f5989d668b70d41 to your computer and use it in GitHub Desktop.
Save amirhp-com/6094b1a97e77d9e77f5989d668b70d41 to your computer and use it in GitHub Desktop.
Get WordPress Custom Posts by Custom Taxonomy Slug
<?php
/**
* Use snippet below to Get WordPress Custom Posts by Custom Taxonomy Slug
* Developed by Amirhosseinhpv ( https://hpv.im/ )
*/
$cpt = "mapify"; // custom post type
$cpt_taxonamy = "mapify_category"; // custom post type taxonamy
$ctp_taxonomy_slug = "official"; // custom post type taxonamy slug
$posts_array = get_posts(
array(
'posts_per_page' => -1,
'post_type' => $cpt,
'fields' => 'ids', // to use fn efficiently and only retrive IDs, otherwise you can comment this line!
'tax_query' => array(
array(
'taxonomy' => $cpt_taxonamy,
'field' => 'slug',
'terms' => $ctp_taxonomy_slug,
)
)
)
);
$posts_count = count($posts_array);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment