As previously announced via banners and our newsletters, support is no longer available through this platform.

For easier navigation, you can still click on "Submit a Ticket" here, choose the appropriate category, and you'll be redirected to the correct support channel for your plugin.

You can still access your previous tickets and browse public tickets, but please note that responding to tickets is no longer possible.

Paid customers: Please log in to your store account for support.

Pre-purchase questions: Use the support widget in the bottom-right corner of our websites:
https://wpamelia.com
https://wpdatatables.com
https://wpreportbuilder.com

Okay
  Public Ticket #2873437
SQL Query dynamic for each page
Closed

Comments

  • Warzone_Loadout started the conversation

    Hello, 

    I have on my website more than 150 pages with some attributes that i would like to display. 

    I use WPDatatable to query my PhPMyAdmin SQL databse and i created some attribute at the POST level. 

    Here is a simple query i have for a dedicated page:

    SELECT `Game`,`Weapon_Category`, `Tier`, `Playstyle` FROM `wp_posts` WHERE `post_title`='PPSH-41';


    This gives me a nice table that i can show on front end for this page. 

    I would like to know if there is a way to automate the query where POST_TITLE = the current page where the table is displayed?

    This would save me a lot of time as otherwise i will need to create 1 table for each page with specific query. 

    Let me know if you have a solution. 

    Sincerely, 

    Alex


  •  2,576
    Aleksandar replied

    Hello Alex.

    We don't have this built-in yet, but you can with a workaround. Please note that this does require some experience with writing SQL queries and using WP hooks.

    You can create a table with a query like this:

    SELECT user_id, user_name, user_address,
    CONCAT('<a href="http:/yoursite.com/your_custom_page?user_id=',user_id,'">Details</a>') AS Details
    FROM your_table_name

    Then, on your_custom_page you will insert a shortcode of the table ID that you need, with a placeholder like this:

    [wpdatatable id=1 var1=1]

    The second table would be created from a query like this:

    SELECT * FROM second_table WHERE user_id = %VAR1%

    After that, you can use a hook for dynamic placeholders:

    function updateVAR1($tableID){
      global $wdtVar1;
          //check is set GET parametar user_id
        if(isset($_GET['user_id'])){
            //get value from form field
            $wdtVar1 = $_GET['user_id'];
        }
      }
    add_action('wpdatatables_before_get_table_metadata', 'updateVAR1');

    I hope this helps you achieve the results that you need.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables