2021年3月8日星期一

WordPress - enable search for custom DB

I am new to WordPress, PHP, and SQL, not much knowledge of coding. I have a MySQL Table, data of a book's pages and lines as rows. The columns are SQ_no, Page_no, Line_no, Verse, VerseTranslationHindi, VerseTranslationEnglish etc. Pages are more than 1000, each page has 50+ verses (Or in this case - rows). I want to display all rows of each page in a post. I used PHP Code Snippets Plugin and a snippet contain this code to fetch data from the table.

global $wpdb; global $post;   $post_slug=$post->post_name;     $result = $wpdb->get_results( "SELECT * FROM book_db where Page_no='$post_slug'");    foreach ($result as $row)   {  echo  $row->Verse;   echo "</br>";   echo  $row->VerseTranslationHindi;   echo "</br>";    echo  $row->VerseTranslationEnglish;   echo "</br>";   }    ?>  

This works great when I call snippet in a post and give it a slug, like page-1, page-2, etc.

However, the problem with this approach is, the WordPress search box does not find any word from the DB. (I guess it's because I have a custom DB. If I place the same data directly in a post, the search shows them ).

My question is, how can I enable search for custom DB? Or is there any better way to do the same thing?

I appreciate any help you can provide.

https://stackoverflow.com/questions/66523682/wordpress-enable-search-for-custom-db March 08, 2021 at 10:39AM

没有评论:

发表评论