• Hi, am able to retrieve and display data from a custom database table in an HTML table using PHP file as a template for a WordPress post ($wpdb->get_results). Have retrieved entries to populate several drop down lists which I want to use to filter SQL query.

    How do you go about passing the selected items in the lists back to construct your SQL string. Have tried adding a submit button and using the POST variable which is presumably the simplest way but if I specify the PHP file as the target action then I just get page not found errors – which seems reasonable as browser is trying to render an HTML page. How do I get the page to refresh on clicking the submit and access the selected items in the drop downs.

    Should I be using some other method entirely to do the filtering? 30 years of programming and I’m scratching my head at this PHP stuff!

    Any pointers would be gratefully appreciated.

    • This topic was modified 2 years, 8 months ago by Jan Dembowski.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    If your PHP needs to use WP resources, even if just $wpdb, you need to direct form action URLs to something that will initialize the WP environment. There are limited ways to do so properly. While including wp-load.php will work, it is discouraged because it’s not fully portable. Submitting back to the same custom page template is one way. That’s specifically a WP page post type template, not any old PHP page. Submitting via admin-ajax.php and Ajax script is another. You can instead submit to admin-post.php and avoid client side scripts, but response is not themed unless your code explicitly manages it.

    For filtering purposes, IMO, building a custom page template and submitting back to it (empty form action attribute) is likely your best option.

    Thread Starter geoffjbaker

    (@geoffjbaker)

    thanks will take another look

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display data from table(s) with option to filter using drop down lists’ is closed to new replies.