Skip to content

Commit

Permalink
Update helper.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazz-Man authored Dec 24, 2019
1 parent 38b9ca9 commit 5e29bbc
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,25 @@ function cpt_get_taxonomy_labels(string $taxonomy_name, $textdomain = 'cpt')
*/
function cpt_get_post_type_archive_post_id(string $post_type)
{
$post_type_archive_id = get_posts([
'fields' => 'ids',
'numberposts' => 1,
'post_type' => 'hdptap_cpt_archive',
'post_status' => 'publish',
'name' => $post_type,
]);

if ( ! empty($post_type_archive_id)) {
return reset($post_type_archive_id);
global $wpdb;

$query = $wpdb->prepare(<<<SQL
SELECT
ID
FROM $wpdb->posts
WHERE
post_status ='publish'
AND post_type = %s
AND post_name = %s
LIMIT 1
SQL
,'hdptap_cpt_archive',$post_type);


$post_type_archive_id = $wpdb->get_var($query);

if ( $post_type_archive_id !== null) {
return (int)$post_type_archive_id;
}

return false;
Expand Down

0 comments on commit 5e29bbc

Please sign in to comment.