SQL Query Search page

by user3533573   Last Updated June 30, 2020 05:08 AM

I am trying to create a Wordpress webpage that has an input text box and a button. what I want to do is take the input text from the text box and use it as a parameter to search a table I put into the website database and print the results on the screen. I tried using PHP to no avail. what is the best to do this? here is the code Search the Film Database [php] global $wpdb; echo 'Search'; $text = sanitize_text_field($_POST['input']); echo $text; $wpdb->query('USE vcuw2938212664'); function myFunction(){ $txt = sanitize_text_field($_POST['input']); echo 'text is "$txt; $query = 'SELECT * FROM documentaries WHERE English_Title = \'%Li%\';'; echo $query; $results = $wpdb->get_results($query); if ($results != Null){ echo "{$results}"; } else { echo 'no results returned'; } } [/php]

Answers 1

you can use WP_Query(); to query the results.

it has an argument 's' => $search_query,

create an input, get the input value, store it in $search_query, then create a query,

$query = new WP_Query( array( 'post_type' => 'post', 's' => $search_query ) );
if ( $query->have_posts() ) : 
     while ( $query->have_posts() ) : $query->the_post();

     // do something...

Aamer Shahzad
Aamer Shahzad
November 08, 2016 16:17 PM

Related Questions

Combine tax_query and meta_query in WP_Query

Updated September 04, 2017 18:08 PM

Show and filter nested custom posts

Updated October 07, 2017 21:08 PM

Calculating Bayesian average for custom post type

Updated March 10, 2017 10:08 AM

Order Posts By Custom Field That is an array of objects

Updated December 06, 2017 00:08 AM

Sorting query_posts() with a complex orderby filter

Updated February 04, 2019 15:08 PM