From: Steve Sutton Date: Thu, 19 Nov 2015 15:37:34 +0000 (-0500) Subject: Block update for separate block pages. X-Git-Tag: v1.4.0^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=c412b70183c479a77440e0263f74335feb417698;p=WP-Plugins%2Fglm-blocks.git Block update for separate block pages. 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. --- diff --git a/controllers/front.php b/controllers/front.php index 0d7de0b..124e761 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -44,9 +44,9 @@ class glm_blocks_front * * @return array */ - public function fetchAllBlocks() + public function fetchAllBlocks($catID = null) { $block = new glm_models_block($this->pluginDirName); - return $block->fetchAllBlocks(); + return $block->fetchAllBlocks($catID); } } diff --git a/glm-blocks.php b/glm-blocks.php index 37cb351..29976e2 100644 --- a/glm-blocks.php +++ b/glm-blocks.php @@ -45,11 +45,11 @@ if (!function_exists('glm_blocks_show')) { } 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); } } diff --git a/models/block.php b/models/block.php index 088f6cf..0788cd4 100644 --- a/models/block.php +++ b/models/block.php @@ -198,15 +198,19 @@ class glm_models_block * @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;