WordPress get post id with matched post content

Is there a way in WordPress so that I would generate a sub-string of a post content and it would give me the post id?

Thanks in advance.

Related posts

1 comment

  1. It can be achieved using awesome WP Query Class of WordPress with search parameter. e.g. Following query will search for any posts with “hello” words in it and display its Post Ids as you needed:

    <?php
         // 's' parameter is for search
        $the_query = new WP_Query( array( 's' => 'hello' ) );
    
           if ( $the_query->have_posts() ) {
              while ( $the_query->have_posts() ) {
                  $the_query->the_post();
         //now we can echo anything we want like e.g. IDs
                  echo get_the_ID();
            }
    
           } else {
                     // no posts found
           }
             /* Restore original Post Data */
             wp_reset_postdata();
    
     ?>
    

Comments are closed.