How can I check if a post with a particular slug or title exists?
You can use get_page_by_title() or get_page_by_path(). By default, both return a page’s WP_Post object, from which you can extract data. If the page doesn’t exist, they’ll return null. You can also use them on post types other than the built-in page. // By slug. $slug = ‘sample-page’; $page_by_slug = get_page_by_path( $slug ); // By title. … Read more