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:

  1. Latest WordPress
  2. Plugin - Awesome Studio (requires PHP 7)
  3. 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

[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,

[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

[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 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.

Categories
Most Popular

Leave a Reply

Your email address will not be published. Required fields are marked *