Last active
July 27, 2020 08:39
-
-
Save amirhp-com/6094b1a97e77d9e77f5989d668b70d41 to your computer and use it in GitHub Desktop.
Get WordPress Custom Posts by Custom Taxonomy Slug
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 | |
/** | |
* 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