PHP code example of juvo / bricks-custom-query
1. Go to this page and download the library: Download juvo/bricks-custom-query library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
juvo / bricks-custom-query example snippets
add_action('init', function() {
juvo\Bricks_Custom_Queries\Query_Registry::getInstance();
});
Query_Registry::set(
'collection_prompts', // Query name
'Collection Prompts', // Query label
function(array $args, \Bricks\Query $query_obj, juvo\Bricks_Custom_Queries\Query $query) { // Callback for query args
return array_merge($args, [
'post_type' => 'posts',
]
);
}
);
enum Query_Type
{
case Post;
case User;
case Term;
case Other;
}
Query_Registry::set(
'collection_prompts', // Query name
'Collection Prompts', // Query label
function(array $args, \Bricks\Query $query_obj, juvo\Bricks_Custom_Queries\Query $query) { // Callback for query args
// Check setting and apply your logic
if (!empty($query_obj->settings['return_all'])) {
$args['posts_per_page'] = -1;
}
return array_merge($args, [
'post_type' => 'posts',
]
);
}
)->set_controls([
'return_all' => [
'label' => esc_html('Return all'),
'type' => 'checkbox',
]
]);