search_posts_backend

Allows processing of URLs to display custom post listing (search) pages in backend. Search parameters must be contained in a URL and must be specified in the form accepted by PHP scripts as an array. The array must be contained in parameter named 'search' and must contain single item with its key matching plugin ID; e.g., ?search[myplugin][key]=myposts&search[myplugin][status]=1.

Blog

Input (passed by reference)

$params array Search parameters array.
$params[plugin][%plugin_id%] array Array passed by means of GET parameters.
… your plugin code …

Output

%plugin_id%][join
Array of JOIN clauses for post selection SQL query in the following format:
array(
    'wa_contact' => array(    //array keys must be table names
        'type' => '', //e;g;, 'LEFT'
        'condition' => array(    //parts of 'ON' condition
            'wa_contact.id = blog_post.contact_id',
            '...',
        ),
        'fields' => array(    //fields of joined table and their aliases to be returned by SQL auery
            'name' => 'contact_name',
            'company',    //if no alias is specified, field name is used as its alias
            '...',
        ),
        'values' => array(    //alternative way to specify list of joined table's fields to be returned
            'name' => 'contact_name',    //in this case aliases are required
            '...',
        ),
    ),
),
%plugin_id%][where
Simple array of WHERE clauses for post selection SQL query:
array(
    'contact_id = 123',
    'LENGTH(TITLE)  > 100',
    '...',
)
%plugin_id%][order
ORDER BY clauses for post selection SQL query.
Blog

Plugin code example

PHP

public function searchPostsBackend($params)
{
    waLog::log(print_r($params, true), 'blog/myplugin/search-posts-backend.log');

    //E.g., display posts added by current user at URL /webasyst/blog/?search[myplugin]=myposts
    if (isset($params['plugin'][$this->id])) {
        $result = array();
        if ($params['plugin'][$this->id] == 'myposts') {
            //adding custom WHERE condition
            $result['where'][] = 'contact_id = '.wa()->getUser()->getId();
            $response = wa()->getResponse();
            $response->setTitle(_wp('My posts'));
        } else {
            //select nothing if incorrect URL parameter value is passed instead of 'myposts'
            $result['where'][] = '0';
        }
        return $result;
    }
}