Job post type is now correctly searching.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 18 Dec 2014 17:17:21 +0000 (12:17 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 18 Dec 2014 17:17:21 +0000 (12:17 -0500)
Was issue with something in the function file in the theme.
Also hiding the view link in the jobs list.

css/glm_jobs.css
models/job.php

index 9992e6e..a4c395d 100644 (file)
@@ -1,7 +1,4 @@
 
-#post-query-submit,
-#post-search-input,
-#wordpress-https,
-#search-submit {
+.wp-list-table span.view {
     display:none;
 }
index 941ea4d..5f35ba7 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 /**
  * Sets up the job post type and its taxonomies. Handles also the new fields in
  * the metaboxes.
@@ -17,6 +18,7 @@ class glm_employment_job
      */
     public function __construct($path)
     {
+//        global $typenow;
         $this->pluginDirName = $path;
         add_action('init', array($this, 'addPostTypes'));
         add_action('init', array($this, 'createJobTaxonomy'));
@@ -24,16 +26,68 @@ class glm_employment_job
         add_filter('post_updated_messages', array($this, 'jobsUpdatedMessages'));
 
         add_filter('manage_edit-glm_jobs_columns',
-                    array($this, 'jobsEditColumns'));
+                   array($this, 'jobsEditColumns'));
 
         add_action('manage_posts_custom_column',
-                    array($this, 'jobsCustomColumns'));
+                   array($this, 'jobsCustomColumns'));
         add_action('admin_init', array($this, 'metaDates'));
         add_action('save_post', array($this, 'saveEmpMeta'));
-        add_filter('manage_edit-glm_jobs_sortable_columns', array($this, 'sortingColumns'));
-//        add_action('restrict_manage_posts', array($this, 'jobFilterList'));
-//        add_filter('parse_query', array($this, 'jobFilter'));
-        add_filter('user_row_actions', array($this, 'remove_row_actions'));
+        add_filter('manage_edit-glm_jobs_sortable_columns',
+                   array($this, 'sortingColumns'));
+        add_action('restrict_manage_posts',
+                   array($this, 'taxonomy_filter_restrict_manage_posts'));
+        add_filter('parse_query', array($this, 'jobFilter'));
+//        var_dump($typenow);
+//        add_filter('user_row_actions', array($this, 'remove_row_actions'));
+    }
+
+    // Filter the request to just give posts for the given taxonomy, if applicable.
+    function taxonomy_filter_restrict_manage_posts()
+    {
+        global $typenow;
+//        var_dump($typenow);
+        if ($typenow == GLM_EMP_POST_TYPE) {
+            $filters = get_object_taxonomies(GLM_EMP_POST_TYPE);
+
+            foreach ($filters as $tax_slug) {
+                $tax_obj = get_taxonomy($tax_slug);
+                wp_dropdown_categories(array(
+                    'show_option_all' => __('Show All ' . $tax_obj->label),
+                    'taxonomy'        => $tax_slug,
+                    'name'            => $tax_obj->name,
+                    'orderby'         => 'name',
+                    'selected'        => $_GET[$tax_slug],
+                    'hierarchical'    => $tax_obj->hierarchical,
+                    'show_count'      => true,
+                    'hide_empty'      => true
+                ));
+            }
+            }
+
+
+
+    }
+
+    function taxonomy_filter_post_type_request($query)
+    {
+        global $pagenow, $typenow;
+//var_dump($typenow);
+        if ('edit.php' == $pagenow && $typenow == GLM_EMP_POST_TYPE) {
+            $filters = get_object_taxonomies(GLM_EMP_POST_TYPE);
+//            var_dump($filters);
+            foreach ($filters as $tax_slug) {
+                $var = &$query->query_vars[$tax_slug];
+//                var_dump($var);
+//                var_dump($tax_slug);
+                if (isset($var)) {
+                    $term = get_term_by('id', $var, $tax_slug);
+                    var_dump($term);
+                    $var['term'] = $term->slug;
+                    var_dump($var['term']);
+                    var_dump($term->slug);
+                }
+            }
+        }
     }
 
     public function remove_row_actions($actions, $post)
@@ -71,32 +125,33 @@ class glm_employment_job
      */
     public function jobFilter($query)
     {
-        if (isset($_REQUEST['post_type']) && $_REQUEST['post_type'] == GLM_EMP_POST_TYPE) {
-            $qv =& $query->query_vars;
+        global $pagenow, $typenow;
+        if ('edit.php' == $pagenow && $typenow == GLM_EMP_POST_TYPE) {
+            $qv = & $query->query_vars;
             if (isset($qv['post_type']) && $qv['post_type'] == GLM_EMP_POST_TYPE) {
+                //$qv['post_type'] = 'page';//GLM_EMP_POST_TYPE;
                 if (isset($qv[GLM_EMP_TAX_CATEGORIES]) && $qv[GLM_EMP_TAX_CATEGORIES] != 0) {
-                    $term = get_term_by('id',$qv[GLM_EMP_TAX_CATEGORIES],GLM_EMP_TAX_CATEGORIES);
+                    $term = get_term_by('id', $qv[GLM_EMP_TAX_CATEGORIES], GLM_EMP_TAX_CATEGORIES);
                     $qv[GLM_EMP_TAX_CATEGORIES] = $term->slug;
 
-//                    if (isset($query->tax_query)) {
-//                        $tax_query =& $query->tax_query;
-//                        $queries =& $tax_query->queries;
-////                        echo '<pre>'.print_r($queries, true).'</pre>';
-//                        foreach ($queries as $key => &$qs) {
-//                            if ($qs['taxonomy'] == GLM_EMP_TAX_CATEGORIES) {
-//                                $qs['terms'][$key] = $term->slug;
-//                            }
-//                        }
-//                    }
+                    if (isset($query->tax_query)) {
+                        $tax_query =& $query->tax_query;
+                        $queries =& $tax_query->queries;
+//                        echo '<pre>'.print_r($queries, true).'</pre>';
+                        foreach ($queries as $key => &$qs) {
+                            if ($qs['taxonomy'] == GLM_EMP_TAX_CATEGORIES) {
+                                $qs['terms'][$key] = $term->slug;
+                            }
+                        }
+                    }
 
                 }
                 if (isset($qv[GLM_EMP_TAX_DEPARTMENTS]) && $qv[GLM_EMP_TAX_DEPARTMENTS] != 0) {
-                    $term = get_term_by('id',$qv[GLM_EMP_TAX_DEPARTMENTS],GLM_EMP_TAX_DEPARTMENTS);
+                    $term = get_term_by('id', $qv[GLM_EMP_TAX_DEPARTMENTS], GLM_EMP_TAX_DEPARTMENTS);
                     $qv[GLM_EMP_TAX_DEPARTMENTS] = $term->slug;
                 }
                 if ($qv['post_type'] == GLM_EMP_POST_TYPE) {
 //                    echo '<pre>'.print_r($qv, true).'</pre>';
-
                 }
 //                echo '<pre>'.print_r($query, true).'</pre>';
             }
@@ -104,7 +159,6 @@ class glm_employment_job
 
             return $query;
         }
-
     }
 
     /**
@@ -123,7 +177,9 @@ class glm_employment_job
                 'taxonomy'        => GLM_EMP_TAX_CATEGORIES,
                 'name'            => GLM_EMP_TAX_CATEGORIES,
                 'orderby'         => 'name',
-                'selected'        => (isset($wp_query->query[GLM_EMP_TAX_CATEGORIES])? $wp_query->query[GLM_EMP_TAX_CATEGORIES]: ''),
+                'selected'        => (isset($wp_query->query[GLM_EMP_TAX_CATEGORIES])
+                    ? $wp_query->query[GLM_EMP_TAX_CATEGORIES]
+                    : ''),
                 'hierarchical'    => true,
                 'depth'           => 3,
                 'show_count'      => true,
@@ -135,7 +191,9 @@ class glm_employment_job
                 'taxonomy'        => GLM_EMP_TAX_DEPARTMENTS,
                 'name'            => GLM_EMP_TAX_DEPARTMENTS,
                 'orderby'         => 'name',
-                'selected'        => (isset($wp_query->query[GLM_EMP_TAX_DEPARTMENTS])? $wp_query->query[GLM_EMP_TAX_DEPARTMENTS]: ''),
+                'selected'        => (isset($wp_query->query[GLM_EMP_TAX_DEPARTMENTS])
+                    ? $wp_query->query[GLM_EMP_TAX_DEPARTMENTS]
+                    : ''),
                 'hierarchical'    => true,
                 'depth'           => 3,
                 'show_count'      => true,
@@ -160,7 +218,7 @@ class glm_employment_job
     public function editJobMeta()
     {
         global $post;
-        $custom  = get_post_custom($post->ID);
+        $custom = get_post_custom($post->ID);
         extract($custom);
 
         $meta_sd = (isset($custom['glm_jobs_startdate']))
@@ -173,25 +231,25 @@ class glm_employment_job
         $clean_sd = date('D, M d, Y', $meta_sd);
         $clean_ed = date('D, M d, Y', $meta_ed);
 
-        $glm_jobs_status = (isset($glm_jobs_status[0]))
+        $glm_jobs_status    = (isset($glm_jobs_status[0]))
             ? $glm_jobs_status[0]
             : '';
         $glm_jobs_pay_grade = (isset($glm_jobs_pay_grade[0]))
             ? $glm_jobs_pay_grade[0]
             : '';
-        $glm_jobs_shift = (isset($glm_jobs_shift[0]))
+        $glm_jobs_shift     = (isset($glm_jobs_shift[0]))
             ? $glm_jobs_shift[0]
             : '';
-        $glm_jobs_contact = (isset($glm_jobs_contact[0]))
+        $glm_jobs_contact   = (isset($glm_jobs_contact[0]))
             ? $glm_jobs_contact[0]
             : '';
-        $glm_jobs_email = (isset($glm_jobs_email[0]))
+        $glm_jobs_email     = (isset($glm_jobs_email[0]))
             ? $glm_jobs_email[0]
             : '';
-        $glm_jobs_comments = (isset($glm_jobs_comments[0]))
+        $glm_jobs_comments  = (isset($glm_jobs_comments[0]))
             ? $glm_jobs_comments[0]
             : '';
-        $glm_jobs_code = (isset($glm_jobs_code[0]))
+        $glm_jobs_code      = (isset($glm_jobs_code[0]))
             ? $glm_jobs_code[0]
             : '';
 
@@ -270,7 +328,7 @@ class glm_employment_job
             'menu_name'          => 'Jobs'
         );
         $args   = array(
-            'label'           => __('Jobs'),
+//            'label'           => __('Jobs'),
             'labels'          => $labels,
             'description'     => 'Stores Jobs and Job data',
             'public'          => true,
@@ -279,13 +337,20 @@ class glm_employment_job
             'supports'        => array('title', 'editor'),
             'has_archive'     => true,
             'menu_icon'       => 'dashicons-businessman',
-            'capability_type' => 'page',
+            'capability_type' => 'post',
             'hierarchical'    => false,
             'rewrite'         => array('slug' => 'jobs'),
             'taxonomies'      => array(GLM_EMP_TAX_CATEGORIES, GLM_EMP_TAX_DEPARTMENTS),
-            'show_in_menu'    => true
+            'show_in_menu'    => true,
+            'show_ui'         => true,
+            'query_var'       => true,
+            'publicly_queryable' => true
         );
         register_post_type(GLM_EMP_POST_TYPE, $args);
+        register_taxonomy_for_object_type(GLM_EMP_TAX_CATEGORIES,
+                                          GLM_EMP_POST_TYPE);
+        register_taxonomy_for_object_type(GLM_EMP_TAX_DEPARTMENTS,
+                                          GLM_EMP_POST_TYPE);
     }
 
     /**
@@ -303,20 +368,32 @@ class glm_employment_job
         global $post, $post_ID;
 
         $messages['post'] = array(
-            0 => '', // Unused. Messages start at index 1.
-            1 => sprintf( __('Job updated. <a href="%s">View item</a>'), esc_url( get_permalink($post_ID) ) ),
-            2 => __('Custom field updated.'),
-            3 => __('Custom field deleted.'),
-            4 => __('Job updated.'),
+            0  => '', // Unused. Messages start at index 1.
+            1  => sprintf(__('Job updated. <a href="%s">View item</a>'),
+                             esc_url(get_permalink($post_ID))),
+            2  => __('Custom field updated.'),
+            3  => __('Custom field deleted.'),
+            4  => __('Job updated.'),
             /* translators: %s: date and time of the revision */
-            5 => isset($_GET['revision']) ? sprintf( __('Job restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
-            6 => sprintf( __('Job published. <a href="%s">View event</a>'), esc_url( get_permalink($post_ID) ) ),
-            7 => __('Job saved.'),
-            8 => sprintf( __('Job submitted. <a target="_blank" href="%s">Preview event</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
-            9 => sprintf( __('Job scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview job</a>'),
-              // translators: Publish box date format, see http://php.net/date
-              date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
-            10 => sprintf( __('Job draft updated. <a target="_blank" href="%s">Preview event</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
+            5  => isset($_GET['revision'])
+                ? sprintf(__('Job restored to revision from %s'),
+                             wp_post_revision_title((int) $_GET['revision'],
+                                                    false))
+                : false,
+            6  => sprintf(__('Job published. <a href="%s">View event</a>'),
+                             esc_url(get_permalink($post_ID))),
+            7  => __('Job saved.'),
+            8  => sprintf(__('Job submitted. <a target="_blank" href="%s">Preview event</a>'),
+                             esc_url(add_query_arg('preview', 'true',
+                                                   get_permalink($post_ID)))),
+            9  => sprintf(__('Job scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview job</a>'),
+                // translators: Publish box date format, see http://php.net/date
+                             date_i18n(__('M j, Y @ G:i'),
+                                          strtotime($post->post_date)),
+                                                    esc_url(get_permalink($post_ID))),
+            10 => sprintf(__('Job draft updated. <a target="_blank" href="%s">Preview event</a>'),
+                             esc_url(add_query_arg('preview', 'true',
+                                                   get_permalink($post_ID)))),
         );
         return $messages;
     }
@@ -346,19 +423,18 @@ class glm_employment_job
         );
 
         register_taxonomy(
-            GLM_EMP_TAX_CATEGORIES,
-            null, //GLM_EMP_POST_TYPE,
+            GLM_EMP_TAX_CATEGORIES, GLM_EMP_POST_TYPE,
             array(
-                'label'        => __('Job Category'),
-                'labels'       => $labels,
-                'hierarchical' => true,
-                'show_ui'      => true,
-                'query_var'    => GLM_EMP_TAX_CATEGORIES,
-                'rewrite'      => array('slug' => GLM_EMP_TAX_CATEGORIES),
-                'show_admin_column' => true,
-                '_builtin' => true
+            'label'             => __('Job Category'),
+            'labels'            => $labels,
+            'hierarchical'      => true,
+            'show_ui'           => true,
+            'query_var'         => GLM_EMP_TAX_CATEGORIES,
+            'rewrite'           => array('slug' => GLM_EMP_TAX_CATEGORIES),
+            'show_admin_column' => true,
+            '_builtin'          => true
         ));
-        register_taxonomy_for_object_type(GLM_EMP_TAX_CATEGORIES, GLM_EMP_POST_TYPE);
+
         $labels = array(
             'name'                       => _x('Departments',
                                                'taxonomy general name'),
@@ -379,17 +455,15 @@ class glm_employment_job
         );
 
         register_taxonomy(
-            GLM_EMP_TAX_DEPARTMENTS,
-            null, //GLM_EMP_POST_TYPE,
+            GLM_EMP_TAX_DEPARTMENTS, GLM_EMP_POST_TYPE,
             array(
-                'label'        => __('Job Department'),
-                'labels'       => $labels,
-                'hierarchical' => true,
-                'show_ui'      => true,
-                'query_var'    => GLM_EMP_TAX_DEPARTMENTS,
-                'rewrite'      => array('slug' => GLM_EMP_TAX_DEPARTMENTS),
+            'label'        => __('Job Department'),
+            'labels'       => $labels,
+            'hierarchical' => true,
+            'show_ui'      => true,
+            'query_var'    => GLM_EMP_TAX_DEPARTMENTS,
+            'rewrite'      => array('slug' => GLM_EMP_TAX_DEPARTMENTS),
         ));
-        register_taxonomy_for_object_type(GLM_EMP_TAX_DEPARTMENTS, GLM_EMP_POST_TYPE);
     }
 
     /**