Created
January 19, 2018 04:37
-
-
Save TanvirAmi/6f7759564d069f8f10b50fea51bbac94 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/* | |
* Returns post IDs in a term with a given ID | |
* | |
* @param int $term_id(Category ID, Tag ID) | |
* | |
* @return array|int Post ID(s) | |
*/ | |
function get_post_id_by_term_id( $term_id ){ | |
global $wpdb; | |
$ids = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term_id ) ); | |
if( count( $ids ) > 1 ) | |
return $ids; // return array | |
else | |
return $ids[0]; // return int | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment