Custom table queries in WordPress - php

I am developing a WordPress site for a client and they would like me to setup a custom page that allows logged in users to query a custom table in the WordPress database. I'll be naming the custom table 'inspectors' and will import the data from a CSV file.
I've found this helpful tutorial on doing this
But the 'fly in the ointment' is that they want the results to be displayed according to location - so the user would enter a postal code or town and will get results for inspectors that are located within a 50 k radius. I'm pretty sure I could manage a basic query to the custom table, but getting it to return location-based results is beyond me.
Is it even possible - and if so, is it worth the time and effort it would take to make it happen - or is there a simple solution I just don't know about?
Also, they also would like me to create a custom form (that is available only to the admin user role) so they can update the info from WordPress and not have to update the info in the spreadsheet. They'd like to be able to export the data in the table to CSV easily too ...
Thanks for any help on this!

Refer the below link and write your own custom queries.
http://codex.wordpress.org/Class_Reference/wpdb

Related

How to Search and fetch result from database other than wordpress in wordpress?

I am new to wordpress coding and need some help regarding fetching some data from different database which is not wordpress database and show on wordpress website. Let me make it more clear,
I have two CMS installed
1. WordPress
2. CRM
In CRM I have some user data which i want to display on wordpress. I searched web but almost each answer is showing retrieving data from wordpress database itself. If you have any way to do it please suggest.
There isn't an "as is" solution, every database structure of every CRM is different.
You will have to create your own custom database queries, and output the data into variables that you can use to create new queries on the other database.
Next, you will want to format your data and present it into a page.
what i understand from your post is thatyou want to show contents of a different database in your wordpress site. i think i have a solution which is not so good but it should work.
you can create a custom plugin for your wordpress. sole purpose of that plugin would be fetching data form that db and show it in you wp site.
make a custom connection in your plugin to connect it with the database you want.

Implement Custom Search Plugin for Joomla

I would like to implement a Custom Search Plugin for Joomla 3.5.1. I am new to Joomla and still busy getting my feet together.
I recently implemented a plugin that adds custom/extra fields (5 fields, free text inputs) to an article in Joomla 3.5.1. I followed their tutorial on how to get this right and so far so good. This plugin saves the extra/custom fields in the #__user_profiles table as per their tutorial. I could obviously save it to a different table but since I am learning, I kept it simple. This plugin works perfectly and I can capture the extra fields and saves successfully and the data is saved along with the article id being edited/created.
My next task is to create another site/front-end "search" (or smart search) plugin. This plugin must group the 4 field's values and provide them to the user in the front-end as selects/dropdowns.
Is there someone that can give me a lead on how I can archive this. Must I implement it as a search or smart search plugin? Is it even possible to archive what I am trying to archive?
This search plugin will only appear on one page but that I know I can config correctly once I've a plugin. Once user searches, the system must post back the selected options and I will search the "#__user_profiles" for any matching profile_key vs profile_value and collect all user_id (article_id) and get these articles from contents table and return this list of articles to the front-end as search results. Anyone can help me into the right direction?
I tried their tutorial of creating a search plugin but I seem lost, mostly I don't know how to dynamically provide my selects/dropdowns with that info saved in the #__user_profiles table.
Please assist in anyway possible...
I don't think that this might be done without modifying core 'search' task. My advise is to advise search view and include extra filtering, then write own 'search' task which allow you to read this data and provide additional results.
By writing just search plugin you can only extend search results by data which is stored outside default Joomla! tables but nothing more.

Adding a mysql table as custom Field in Smart Search(Joomla)

Can anyone please guide me how to create a custom field (search filter) on joomla.
I want to create a custom filter from which i can select any particular table to search items in that table. Kindly refer to the screenshot i have attached.
I am a beginner to joomla & PHP.
I want to incorporate the search in the core joomla smart search or if there is any problem with that than i dont have any problem in having a dedicated page on the site.
I have 8-9 tables with 5-6K records for which i want to search the data. User will search some keywords and filter it with the table name present in mysql database. Search will use that particular table selected. Only particular users having access to that page will be using that search. At most 2-3 people will be having access to search.
What i am concerned is about the process of creating a custom field with drop down field of table in mysql DB. I tried searching but i didn't got any specific information. I have the knowledge on OOP methodologies but not much on MVC. Kindly suggest.
What you want to do can be done but will require a functional understanding of both OOP methodologies and MVC principles.
You can create a custom field to generate the drop down field of tables to search.
The next part depends on how you want to incorporate the feature into your website. Do you want it to be part of the core Joomla search or have a dedicated view for it.
Another major programming obstacle is how to generate the table search queries in a way that doesn't require you to build out complicated and difficult to maintain query generation code for each table. Otherwise any tables not explicitly codes for would not be part of search until you updated code.
I would edit your question with following information:
where and how will user search
does search need to list all tables and search all
Is this something you want to expose to the public, or a tool for Admins.

Wordpress plugin to automate posts being generated based on backend tables?

I am a long time Wordpress user looking to use the tool as a CMS to generate a website which will have individual posts about hundreds of specs on products that I have stored in a backend MySQL table. Is there a plugin or a tool that will help me auto generate these posts? For each post, I would like it to have the same format of title (one column) so that the URL will look like: http://www.domain.com/product1specs etc. Each post will contain a description (another column) and show a graph (data stored in another column).
Or do I even need to create posts? Is there a way to do this dynamically? So if someone goes to www.domain.com/product1 than it will automatically look in the database to find out what it should display for product1?
I believe there are other ways to do this with an PHP framework such as Code Igniter but I would like to stick with Wordpress because I am familiar with it and have other Wordpress plugins/themes I would like to leverage.
Any tips would be greatly appreciated!
I don't know of a plugin but take a look at this answer which basically required the same thing:
How to migrate from Yii to Woocommerce Wp, Still keep to old database (table,rows)

Creating WP custom post types with custom fields from database

I'm working on a Wordpress website that uses an external system to sell tickets. This ticket system provides a WordPress plugin that automatically creates and updates two new WordPress database tables: events and shows. That's great, but that's all this plugin does.
I have used the Database Browser plugin to test if the database tables created by the ticket system plugin were there and that was the case. I can see all the data there too. So far so good.
I now need to create custom post types (events and shows) with custom fields using the data from these database tables. I've searched, but I can't seem to find out how to create custom post types that pull their data from existing database tables.
Maybe I'm looking at this all wrong. Any help to point me in the right direction?
To create custom post refer this http://codex.wordpress.org/Post_Types#Custom_Post_Types
And use this plugin to create custom field http://wordpress.org/plugins/advanced-custom-fields/
i'm assuming you realise that you'll need to write code to query db...there are no plugins to query a db (that i know of).
it also sounds like you are going to duplicate data ie pull data from custom table events and shows, then add to this data to custom fields. i'm not sure this is the best approach.
also, if data in these custom tables change, will it be reflected in your custom fields data?
have i assumed too much? let me know.
To query db, use the wp class wpdb. I havent really used it but it has enough features to do what you want.
acf plugin has already been mentioned. custom post type ui plugin is easy for creating custom post types with no code. it even prints out the actual code for you so you can copy it, place in functions.php, then disable plugin, nice.

Categories