Title: Scriptrunner (Doug Sparling)'s Replies - page 18 | WordPress.org

---

# Scriptrunner (Doug Sparling)

  [  ](https://wordpress.org/support/users/scriptrunner/)

 *   [Profile](https://wordpress.org/support/users/scriptrunner/)
 *   [Topics Started](https://wordpress.org/support/users/scriptrunner/topics/)
 *   [Replies Created](https://wordpress.org/support/users/scriptrunner/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/scriptrunner/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/scriptrunner/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/scriptrunner/engagements/)
 *   [Favorites](https://wordpress.org/support/users/scriptrunner/favorites/)

 Search replies:

## Forum Replies Created

Viewing 15 replies - 256 through 270 (of 520 total)

[←](https://wordpress.org/support/users/scriptrunner/replies/page/17/?output_format=md)
[1](https://wordpress.org/support/users/scriptrunner/replies/?output_format=md) 
[2](https://wordpress.org/support/users/scriptrunner/replies/page/2/?output_format=md)
[3](https://wordpress.org/support/users/scriptrunner/replies/page/3/?output_format=md)…
[17](https://wordpress.org/support/users/scriptrunner/replies/page/17/?output_format=md)
18 [19](https://wordpress.org/support/users/scriptrunner/replies/page/19/?output_format=md)…
[33](https://wordpress.org/support/users/scriptrunner/replies/page/33/?output_format=md)
[34](https://wordpress.org/support/users/scriptrunner/replies/page/34/?output_format=md)
[35](https://wordpress.org/support/users/scriptrunner/replies/page/35/?output_format=md)
[→](https://wordpress.org/support/users/scriptrunner/replies/page/19/?output_format=md)

 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Fatal error — I have no idea how to resolve this!](https://wordpress.org/support/topic/fatal-error-i-have-no-idea-how-to-resolve-this/)
 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/fatal-error-i-have-no-idea-how-to-resolve-this/#post-4188508)
 * Ah, just reread your initial message. From the error message, it looks like the
   theme itself is causing the issue:
 * > Fatal error: Cannot redeclare add_unlink_script() (previously declared in /
   > home/content/06/9931306/html/wp-content/themes/Metrolium/functions.php:554)
   > in /home/content/06/9931306/html/wp-content/themes/Metrolium/backend/functions.
   > php on line 55
 * so
 * `add_unlink_script()` appears to be declared both in
 * wp-content/themes/Metrolium/functions.php (line 554)
 * and in
 * wp-content/themes/Metrolium/backend/functions.php (line 55)
 * Does the site that does work with this theme have the same version of the theme
   and can you check if it has the two function.php files…and if they both contain
   an `add_unlink_script` function?
 * Beyond that, you’ll have to check with the theme author.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Fatal error — I have no idea how to resolve this!](https://wordpress.org/support/topic/fatal-error-i-have-no-idea-how-to-resolve-this/)
 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/fatal-error-i-have-no-idea-how-to-resolve-this/#post-4188503)
 * As a quick test, disable all your plugins on the install throwing the error.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Fatal error — I have no idea how to resolve this!](https://wordpress.org/support/topic/fatal-error-i-have-no-idea-how-to-resolve-this/)
 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/fatal-error-i-have-no-idea-how-to-resolve-this/#post-4188502)
 * Are you using the exact same plugins on the other install? It only happens if
   there’s a conflict and it’s most likely a conflict between the theme and a plugin.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Fatal Error??](https://wordpress.org/support/topic/fatal-error-924/)
 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/fatal-error-924/#post-4188500)
 * Is this a new install? It’s possible something may have gotten corrupted or not
   installed. In particular, see if you have:
 * `wp-includes/cache.php`
 * in your install. That’s where the wp_cache_init function is defined.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Fatal error — I have no idea how to resolve this!](https://wordpress.org/support/topic/fatal-error-i-have-no-idea-how-to-resolve-this/)
 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/fatal-error-i-have-no-idea-how-to-resolve-this/#post-4188497)
 * Themes and plugins (and WordPress itself) contain functions, and unless they 
   are name spaced (usually by using Object Oriented programming style), then if
   any two functions from separate sources have the same name there will be a “name
   collision” and you’ll see that error. Generally which ever function is found 
   first “wins” the other(s) will throw an error saying the function name cannot
   be redeclared. `add_unlink_script` is a pretty generic name. Plugin and theme
   authors will usually add a prefix related to their plugin or theme to make name
   collision less likely to happen. The author needs to update the name of that 
   function, say to something like:
 * `metrolium_add_unlink_script`
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Get multiple category names inside the loop](https://wordpress.org/support/topic/get-multiple-category-names-inside-the-loop/)
 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/get-multiple-category-names-inside-the-loop/#post-4188458)
 * Your answer was right there in the [Codex: Function Reference/get the category](http://codex.wordpress.org/Function_Reference/get_the_category)
   page under the “Show All Categories as Links” section 🙂
 * Slightly modified/simplified:
 *     ```
       <?php
       $categories = get_the_category();
       if( $categories ) {
           foreach( $categories as $category ) {
               echo "$category->name<br />";
           }
       }
       ?>
       ```
   
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Can't get Read more… link towork from excerpt](https://wordpress.org/support/topic/cant-get-read-more-link-towork-from-excerpt/)
 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/cant-get-read-more-link-towork-from-excerpt/#post-4187170)
 * As a general rule, non-WordPress.org themes aren’t supported in these forums.
 * But as a theme-agnostic solution, you might try this:
 *     ```
       <p><a href="<?php echo get_permalink( get_the_ID() ); ?>">Read more...</a></p>
       ```
   
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Is there anyway to moderate use of shortcodes in wordpress?](https://wordpress.org/support/topic/is-there-anyway-to-moderate-use-of-shortcodes-in-wordpress/)
 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/is-there-anyway-to-moderate-use-of-shortcodes-in-wordpress/#post-4163451)
 * Try this in your theme’s functions.php:
 *     ```
       function filter_handler( $data , $postarr ) {
           if ( !current_user_can( 'manage_options' ) ) {
               $data['post_content'] = preg_replace( "/\[([^\[\]]++|(?R))*+\]/", "", $data['post_content'] );
           }
           return $data;
       }
       add_filter( 'wp_insert_post_data', 'filter_handler', '99', 2 );
       ```
   
 * This will prevent anyone other than admin/superadmin from inserting shortcodes(
   well, it will delete a pair of square brackets and anything in between when a
   non-admin inserts or updates a page/post – if there’s a better way I haven’t 
   found it yet).
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Blog Died After Upgrade!](https://wordpress.org/support/topic/blog-died-after-upgrade/)
 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/blog-died-after-upgrade/#post-4163987)
 * Check your wp-config.php file and make sure everything with regards to the database
   is correct. (database name, host, username, password) If any of those items are
   wrong, then you will get the message:
 * `Error establishing a database connection`
 * You would also get that error if MySQL itself wasn’t running.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Exclude Single Post View of Certain Categories](https://wordpress.org/support/topic/exclude-single-post-view-of-certain-categories/)
 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/exclude-single-post-view-of-certain-categories/page/2/#post-4176954)
 * I think you should be able to add this to your functions.php in your theme to
   disable cache:
 *     ```
       define(‘MAGPIE_CACHE_ON’, 0);
       ```
   
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Exclude Single Post View of Certain Categories](https://wordpress.org/support/topic/exclude-single-post-view-of-certain-categories/)
 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/exclude-single-post-view-of-certain-categories/page/2/#post-4176953)
 * WordPress caches feeds for one hour, so that may be the issue with that.
 * If you go to the single post page, you should get a 404. If you go to the category
   page for the excluded category, then you’ll get a page with not posts. Same with
   search. Feeds should also exclude those posts in those categories (with the caveat
   that feeds cache).
 * What I do is this. I comment out this line:
 *     ```
       //add_action( 'pre_get_posts', 'exclude_post_by_category' );
       ```
   
 * and then go to a category that I want to be excluded (but since the code is commented
   out, the post(s) for that category should be listed).
 * So, in my case, I go here (I’m using Posts Names for permalins):
 * `http://localhost/category/uncategorized/`
 * and I see my posts.
 * I click on any individual post on the category page, for example
 * `http://localhost/test-post-2/`
 * and I see the post.
 * Now I uncomment that line in functions.php:
 *     ```
       add_action( 'pre_get_posts', 'exclude_post_by_category' );
       ```
   
 * and the go back to the category page and refresh, and voila, no posts show (I
   get: “Nothing Found – It seems we can’t find what you’re looking for. Perhaps
   searching can help.”)
 * I then go forward in browser history to the single post page (`http://localhost/
   test-post-2/`) and it get a 404.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Exclude Single Post View of Certain Categories](https://wordpress.org/support/topic/exclude-single-post-view-of-certain-categories/)
 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/exclude-single-post-view-of-certain-categories/page/2/#post-4176951)
 * I just double checked trying both Default and Post Name permalink settings and
   in both cases it removed the posts (in the exclusion array) from the feed, the
   category page (and since it’s by category, the page simply had no posts), the
   blog posts page, and of course the individual posts.
 * I used Twenty Thirteen theme, no plugins, and the last “full” code I posted. 
   The code I posted before that would just hide the post itself.
 * This is the code you should use, and no additional plugins to hide category.
 *     ```
       function exclude_post_by_category( $query ) {
           $excluded_category_ids = array(1);
           if ( $query->is_main_query() ) {
               if ( ( $query->is_home() || $query->is_category() || $query->is_archive() || $query->is_feed() ) || ( !is_admin() && $query->is_search() ) ) {
                   $query->set('category__not_in', $excluded_category_ids);
               } else if ( $query->is_single() ) {
                   if ( ( $query->query_vars['p'] ) ) {
                       $page= $query->query_vars['p'];
                   } else if ( isset( $query->query_vars['name'] ) ) {
                       $page_slug = $query->query_vars['name'];
                       $post_type = 'post';
                       global $wpdb;
                       $page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type= %s AND post_status = 'publish'", $page_slug, $post_type ) );
                   }
                   if ( $page ) {
                       $post_categories = wp_get_post_categories( $page );
                       foreach ($excluded_category_ids as $category_id ) {
                           if ( in_array( $category_id, $post_categories ) ) {
                               $query->set( 'p', -$category_id );
                               break;
                           }
                       }
                   }
               }
           }
       }
       add_action( 'pre_get_posts', 'exclude_post_by_category' );
       ```
   
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Exclude Single Post View of Certain Categories](https://wordpress.org/support/topic/exclude-single-post-view-of-certain-categories/)
 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/exclude-single-post-view-of-certain-categories/page/2/#post-4176948)
 * Are you using the last code I posted? (the “I believe should be the full code”
   code) That should be used without any other plugins. Now that it’s morning, I’ll
   give it one more check with all permalink types.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Exclude Single Post View of Certain Categories](https://wordpress.org/support/topic/exclude-single-post-view-of-certain-categories/)
 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/exclude-single-post-view-of-certain-categories/page/2/#post-4176946)
 * And I believe this should be the code in full:
 *     ```
       function exclude_post_by_category( $query ) {
           $excluded_category_ids = array(1);
           if ( $query->is_main_query() ) {
               if ( ( $query->is_home() || $query->is_category() || $query->is_archive() || $query->is_feed() ) || ( !is_admin() && $query->is_search() ) ) {
                   $query->set('category__not_in', $excluded_category_ids);
               } else if ( $query->is_single() ) {
                   if ( ( $query->query_vars['p'] ) ) {
                       $page= $query->query_vars['p'];
                   } else if ( isset( $query->query_vars['name'] ) ) {
                       $page_slug = $query->query_vars['name'];
                       $post_type = 'post';
                       global $wpdb;
                       $page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type= %s AND post_status = 'publish'", $page_slug, $post_type ) );
                   }
                   if ( $page ) {
                       $post_categories = wp_get_post_categories( $page );
                       foreach ($excluded_category_ids as $category_id ) {
                           if ( in_array( $category_id, $post_categories ) ) {
                               $query->set( 'p', -$category_id );
                               break;
                           }
                       }
                   }
               }
           }
       }
       add_action( 'pre_get_posts', 'exclude_post_by_category' );
       ```
   
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Exclude Single Post View of Certain Categories](https://wordpress.org/support/topic/exclude-single-post-view-of-certain-categories/)
 *  [Scriptrunner (Doug Sparling)](https://wordpress.org/support/users/scriptrunner/)
 * (@scriptrunner)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/exclude-single-post-view-of-certain-categories/page/2/#post-4176945)
 * Yep, that was it…and a little more complicated than I thought. This seems to 
   work for me using different permalink structures:
 *     ```
       function exclude_single_post( $query ) {
           $excluded_category_ids = array(1);
           if ( $query->is_single() ) {
               if ( ( $query->query_vars['p'] ) ) {
                   $page = $query->query_vars['p'];
               } else if ( isset( $query->query_vars['name'] ) ) {
                   $page_slug = $query->query_vars['name'];
                   $post_type = 'post';
                   global $wpdb;
                   $page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type= %s AND post_status = 'publish'", $page_slug, $post_type ) );
               }
   
               if ( $page ) {
                   $post_categories = wp_get_post_categories( $page );
                   foreach ($excluded_category_ids as $category_id ) {
                       if ( in_array( $category_id, $post_categories ) ) {
                           $query->set( 'p', -$category_id );
                           break;
                       }
                   }
               }
           }
       }
       add_action( 'pre_get_posts', 'exclude_single_post' );
       ```
   

Viewing 15 replies - 256 through 270 (of 520 total)

[←](https://wordpress.org/support/users/scriptrunner/replies/page/17/?output_format=md)
[1](https://wordpress.org/support/users/scriptrunner/replies/?output_format=md) 
[2](https://wordpress.org/support/users/scriptrunner/replies/page/2/?output_format=md)
[3](https://wordpress.org/support/users/scriptrunner/replies/page/3/?output_format=md)…
[17](https://wordpress.org/support/users/scriptrunner/replies/page/17/?output_format=md)
18 [19](https://wordpress.org/support/users/scriptrunner/replies/page/19/?output_format=md)…
[33](https://wordpress.org/support/users/scriptrunner/replies/page/33/?output_format=md)
[34](https://wordpress.org/support/users/scriptrunner/replies/page/34/?output_format=md)
[35](https://wordpress.org/support/users/scriptrunner/replies/page/35/?output_format=md)
[→](https://wordpress.org/support/users/scriptrunner/replies/page/19/?output_format=md)