Since the WordPress API has changed, you cannot use get_posts with the "post_name" parameter. I changed the Martens function a bit:
function get_post_id_by_slug( $slug, $post_type = "post" ) { $query = new WP_Query( array( 'name' => $slug, 'post_type' => $post_type, 'numberposts' => 1, 'fields' => 'ids', ) ); $posts = $query->get_posts(); return array_shift( $posts ); }
Nurickan Jan 30 '18 at 10:26 2018-01-30 10:26
source share