Documentation / Tutorials / Tutorials & How to’s
Manage using API
/ Tutorials & How to’s / Manage using API
What is Manage?
Well, Manage is something that manages your post data. It displays the data of a particular post in a tabular format. You can also get the filtered records with the help of form. One can save the records into the excel and download the excel file.
Below are the prerequisites:
- Latest WordPress
- Plugin - Awesome Studio (requires PHP 7)
- Theme - Monomyth
Once your are done with all the above, edit you user account and grant yourself "Developer Access" under "Awesome UI Control"
Now that we have all the set up ready, lets build our manage screen.
Manage without a form
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[api search.create] [args] [atts auto_handler=table/] [on_submit] [query type=linear] [query new type=sql pagesize=5 pageno='{api_data.pageno}'] [published_posts post_type='loans' /] [add_field new meta_key=customer_id /] [/query] [query new type=select_meta] [select new only_column=yes special=sno label='SNo' /] [select new meta_key='applicant_name' label='Applicant name' ref_id='customer_id'/] [select new taxonomy='loan_type' label='Loan Type' /] [select new field='post_date' label='Date' /] [/query] [/query] [handler table type=search.table /] [/on_submit] [/args] [/api] |
In the above example, we are fetching all the records from the post_type 'loans'. There is no form that further filters the query data.
The basic query that is generated here is,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[query new type=sql pagesize=5 pageno='{api_data.pageno}'] [published_posts post_type='loans' /] [add_field new meta_key=customer_id /] [/query] select q1.* from (select q1.*,q2.customer_id from (Select ID as primary_id from wp_posts where post_type='loans' and post_status='publish') q1 left join (select post_id as primary_id, meta_value as customer_id from wp_postmeta where meta_key='customer_id') q2 on q1.primary_id = q2.primary_id) q1 limit 0,5 |
The above query will give the primary_ids of the post and related customer_ids.
The result of this query is passed to the next query i.e., select_meta
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
[query new type=select_meta] [select new only_column=yes special=sno label='SNo' /] [select new meta_key='applicant_name' label='Applicant name' ref_id='customer_id'/] [select new taxonomy='loan_type' label='Loan Type' /] [select new field='post_date' label='Date' /] [/query] SELECT 'customer_id' as ref_field,post_id as ref_id, meta_key as meta_key,meta_value as meta_value FROM wp_postmeta as a1 where meta_key in('applicant_name') and post_id in ('50404','50291','50387','50393','50363') // customer_id fetched from the basic query UNION SELECT 'primary_id' as ref_field, object_id as ref_id,taxonomy as meta_key,name as meta_value FROM all_terms as a1 where taxonomy='loan_type' and object_id in ('21233','21451','21480','21687','21849') // primary_id fetched from the basic query UNION SELECT 'primary_id' as ref_field,id as ref_id, 'post_date' as meta_key,post_date as meta_value FROM wp_posts as a1 where id in ('21233','21451','21480','21687','21849') // primary_id fetched from the basic query |
select_meta basically takes the columns that is to be displayed in the table.
The manage screen:
Note, As we have set pagesize=5, that is why we can see 5 rows on each page.
Few random samples, writing a custom query for the table
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
[query type=linear] [query new type=sql pagesize=50 pageno='{api_data.pageno}'] [sql]SELECT ID as primary_id FROM wp_posts WHERE ID NOT IN( SELECT ID FROM wp_posts wp LEFT JOIN wp_term_relationships wptr ON wp.ID=wptr.object_id WHERE wptr.term_taxonomy_id IN(56) AND post_type='ment_log' AND post_status='publish' ) AND post_type='ment_log' AND post_status='publish'[/sql] [add_field new meta_key=object_id /] [add_field new field=post_date /] [order field='primary_id DESC'/] [filter new taxonomy=payment_type term='{api_data.payment_type}' operator="in" /] [filter new meta_key='object_id,name,email,phone,ref_no,amount,invoice_number' operator='like' meta_value='{api_data.search}' /] [do not_empty="{api_data.after_date}{api_data.before_date}"] [filter new after_date='{api_data.after_date}' before_date="{api_data.before_date}" field=post_date /] [/do] [do not_empty="{api_data.select_period}"] [aw2.get api_data.select_period separator=':' set=module.temp_list/] [filter new period='{module.temp_list.0}' which="{module.temp_list.1}" field=post_date /] [/do] //** [do empty="{api_data.select_period}"] [filter new period='days' which="7" field=post_date /] [/do] **// [/query] |
Another full working demo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
[api search.create auto_handler=table] [args] [form] [atts form_type='columnar' divider=3/] [control search type=text label='Search' /] [control post_status type=select label='Select Status'] [query type=sql] [pagesize]100[/pagesize] [sql] SELECT distinct(post_status) as name, post_status as value FROM wp_posts where post_type='as_events' [/sql] [/query] [/control] [handler table label='Search' /] [handler xls label='Excel' /] [/form] [on_submit] [query type=linear] [query new type=sql pagesize=50 pageno='{api_data.pageno}'] [sql]Select ID as primary_id from wp_posts where post_type='as_events' [/sql] [filter new field="post_status" field_value="{api_data.post_status default=publish}" /] [/query] [query new type=select_meta] [select new only_column=yes special=sno label='SNo' /] [select new field='post_title' label='Event Name' /] [select new field='post_status' label='Event Status' /] [/query] [/query] [handler table type=search.table /] [handler xls type=search.excel file_name="{api_data.event_title}.xlsx" /] [/on_submit] [/args] [/api] |