Ability to fetch blocks by their parent block id.
if fetch all blocks is given an id it is given into query as post_parent
so only the children of that id given will be fetched.
*
* @return array
*/
- public function fetchAllBlocks()
+ public function fetchAllBlocks($catID = null)
{
$block = new glm_models_block($this->pluginDirName);
- return $block->fetchAllBlocks();
+ return $block->fetchAllBlocks($catID);
}
}
}
if (!function_exists('fetch_all_glm_blocks')) {
- function fetch_all_glm_blocks()
+ function fetch_all_glm_blocks($catId = null)
{
$frontController = new glm_blocks_front(
plugin_dir_path(__FILE__)
);
- return $frontController->fetchAllBlocks();
+ return $frontController->fetchAllBlocks($catId);
}
}
* @access public
* @return void
*/
- public function fetchAllBlocks()
+ public function fetchAllBlocks($catId = null)
{
global $wpdb, $wp;
+ $catId = filter_var($catId, FILTER_VALIDATE_INT);
$args = array(
'posts_per_page' => -1,
'post_type' => GLM_BLOCK_POST_TYPE,
'orderby' => 'menu_order post_title',
'order' => 'asc'
);
+ if ($catId) {
+ $args['post_parent'] = $catId;
+ }
$blocks = get_posts($args);
foreach ($blocks as $block) {
$block->externalUrl = false;