I have been trying to get the page ID of which it contains shortcode. I 'm getting null. Not sure what I'm doing wrong.
function availabilty_id() {
global $template_id;
// Custom Query to look only in pages post type
$template_query = new WP_Query(
array(
'post_type' => 'page',
)
);
if ( $template_query->have_posts() ) {
while ( $template_query->have_posts() ) {
$template_query->the_post();
$post_content = get_the_content();
if ( has_shortcode( $post_content, 'availability' ) ) {
$template_id = get_the_ID();
//var_dump($template_id);
}
}
wp_reset_postdata();
}
}
add_action( 'init', 'availabilty_id' );