Search for page by content
-
I’m trying to find if a page exists and I’m using this clumsy code:
function searchPageContent($contents){ $pages=new WP_Query( array('post_type'=>'page') ); if($pages->have_posts()){ while($pages->have_posts()){ $pages->the_post(); $PID=$pages->post->ID; $post=$pages->posts[0]->post_content; if(substr($post, 0, strlen($contents)) === $contents){ return $PID; } } } return 0; }
If the page exists which starts with the required content, it returns the Page ID.
This seems to work but is awfully clumsy.
Is there a better way?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Search for page by content’ is closed to new replies.