Block update for separate block pages.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 19 Nov 2015 15:37:34 +0000 (10:37 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 19 Nov 2015 15:37:34 +0000 (10:37 -0500)
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.

controllers/front.php
glm-blocks.php
models/block.php

index 0d7de0b..124e761 100644 (file)
@@ -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);
     }
 }
index 37cb351..29976e2 100644 (file)
@@ -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);
     }
 }
index 088f6cf..0788cd4 100644 (file)
@@ -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;