Skip to content

Instantly share code, notes, and snippets.

@georgestephanis
georgestephanis / does_db_have_cpt.php
Created November 12, 2013 16:34
Useful as part of a nest of toggles as to whether a CPT should be defined. For example, whether the theme supports it, or whether something filters it active, or ~this~.
<?php
function get_all_cpts_in_db() {
global $wpdb;
if ( false === ( $cpts = get_transient( 'all_cpts_in_db' ) ) {
$cpts = $wpdb->get_col( "SELECT DISTINCT( `post_type` ) FROM {$wpdb->posts}" );
set_transient( 'all_cpts_in_db', $cpts );
}
return (array) $cpts;
}