Okay
  Public Ticket #2294428
Pre filtering based on a WordPress variable
Closed

Comments

  • Adam Helman started the conversation

    Hi

    Just purchased your plugin - so I'm still getting to grips with it. I was using a Google inline viewer plugin which does actually work how I want, but is very inflexible in other ways, hence jumping ship to you. But I do need to find a way to do what they do with your plugin

    So, I have a Google Sheets table that holds a summary of all my customer invoices (one record for every invoice and each record holds: company name, link to the invoice, date, amount, and payment status).

    I want a logged in customer to only be able to see their invoices.

    I have a custom field on the User post type that holds a company name which I can access via the $cur_user->company variable.

    I can see I can pre-filter using your URL method, however I can see nothing stopping the customer deleting that bit of the URL, and then seeing the whole table.

    So, is there a way to pre-filter based on a WordPress variable (so it's truly dynamic and unalterable), or perhaps some other way?

    I thought placeholders might be the way to go, but was unsure as it looks like anything provided there is a "literal", i.e. no variables etc

    I'm open to hooks etc in function.php...

    Thanks

  •  681
    Aleksandar replied

    Hello Adam

    Thank you for your purchase.

    Please take a look at the Users See and Edit Only Own Data" feature. When you add an integer ID column, and enable this feature, your users would be able to see only those rows which have their ID in the ID column. However, this option is only available for editable tables, and tables linked to an existing data source are somewhat limited, so this wouldn't be possible to achieve.

    You could use the placeholders as a filtering value, but you would still need the ID column. Then, when you go to column settings, you can simply add the %CURRENT_USER_ID% placeholder as a prefiltered value:

    4729459905.png

    It will filter the data, showing only rows where the currently logged-in user's ID is located.

    In front-end, though, you should hide the filter with some simple CSS, so people cannot change the filter. I can help you with that once you publish the page.

    Kind Regards, 

    Aleksandar Vuković
    aleksandar.vukovic@tms-outsource.com

    We would like to improve our plugins to help you adapt to the current working conditions, changed due to COVID-19 quarantines. Let us know which features are missing currently to make your remote work more comfortable. Please take wpDataTables Survey and Amelia Survey, it won't be longer than 3 - 5 minutes. Thank you!

    wpDataTables: FAQFacebookTwitterFront-end and back-end demoDocs

    Amelia: FAQFacebookTwitterAmelia demo sites | Docs

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

    Powerful FiltersGravity Forms Integration for wpDataTablesFormidable Forms Integration for wpDataTables

  •   Adam Helman replied privately
  •   Aleksandar replied privately
  •   Adam Helman replied privately
  •   Milan replied privately
  • Adam Helman replied

    Hi Milan

    My apologies - try again now please (forgot to add your user to the page)

  •   Milan replied privately
  •   Adam Helman replied privately
  •  412
    Milan replied

    HI  Adam,

    1) Yes if you import data from that Google sheet it will be created table in database and that table WILL NOT be sync with that Google sheet anymore. If you need to be sync this table and that Google sheet then you need to find a way how to sync them. That is out of functionality of your plugin so you need to find a way with other solution.

    2) and 3) No, sorry for confusion. If you re using placeholders in queries like

    SELECT * FROM your_table_name WHERE your_column_name = ' %VAR1%'

    And you fill that value for VAR1 in backend then this table will be filtered on back-end and frond-end as well. You are able to overwrite that value throw shortcode on front-end like

    [wpdatatable id=1 var1=YourNewValue] and that value will be used in query and table will be filtered based on that new value.

    If you need to use dynamic VAR1 then you need to use hook that I provide to you in previous post. At the moment with this hook placeholders will be updated on back end but you will be added that hook in file wp-content/plugins/wpdatatables/controllers/wdt_functions.php around line 557 and then this will work on both sides.

    This hook we already add in our plugin and it will be available in next update so you don't have to worry about that.

    You will use this hook in child theme of your main theme so it will not be overwritten when you update your theme.

    --------------------------------------------------------------------------------------------------------------------------------------------------------------

    So if you import data from that Google sheet you will not need to use hooks because you are able to provide value for placeholders (VAR1, VAR2 or VAR3) that you need on shortcode in front-end.

    Best regards.

    Kind Regards, 

    Milan Jovanović

    wpDataTables: FAQFacebookTwitterFront-end and back-end demoDocs

    Amelia: FAQFacebookTwitter |  Amelia demo sites | Docs

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

    Powerful FiltersGravity Forms Integration for wpDataTablesFormidable Forms Integration for wpDataTables

  • Adam Helman replied

    Thanks Milan

    Okay I'll see if I can get it to do what I need :-)

    My biggest concern was amending plugin code, but now I know it'll be part of the "core" I'm much happier!

    I'll let you know if I hit any snags.

  • Adam Helman replied

    In addition to my last reply - one other question please. If I use the Wizard to import (option 3), where in MySQL will table be found? Thanks

  • Adam Helman replied

    Never mind - found it :-)

  •  681
    Aleksandar replied

    And again, Adam - great news!

    Thank you for letting us know.

    If you have any further questions or issues, please feel free to open a new ticket, and we'll gladly help.

    Best regards.

    Kind Regards, 

    Aleksandar Vuković
    aleksandar.vukovic@tms-outsource.com

    We would like to improve our plugins to help you adapt to the current working conditions, changed due to COVID-19 quarantines. Let us know which features are missing currently to make your remote work more comfortable. Please take wpDataTables Survey and Amelia Survey, it won't be longer than 3 - 5 minutes. Thank you!

    wpDataTables: FAQFacebookTwitterFront-end and back-end demoDocs

    Amelia: FAQFacebookTwitterAmelia demo sites | Docs

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

    Powerful FiltersGravity Forms Integration for wpDataTablesFormidable Forms Integration for wpDataTables