Title: ne0que's Replies | WordPress.org

---

# ne0que

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

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

 Search replies:

## Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [How do I create a new page with the plugin I’m building](https://wordpress.org/support/topic/how-do-i-create-a-new-page-with-the-plugin-im-building/)
 *  [ne0que](https://wordpress.org/support/users/ne0que/)
 * (@ne0que)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/how-do-i-create-a-new-page-with-the-plugin-im-building/#post-1302246)
 * Hi there,
 * I used this topic for creating my own plugin. Everything works so far, but when
   i go to the main page on my sandbox.. i see the hello world post. When i click
   on it, i am in the ‘hello world’ post, but the title and the content has been
   replaced by the plugin page post.
 * If you download this code and put it as memberlist.php in your plugin folder 
   of your sandbox you will see what i mean.
 * This is really weird. This is the code, i know it is not documented very well,
   but the class name says enough. I want to create a ‘memberlist’ page where i 
   output all the members in a (paged) list. I start documenting the class when 
   everything works.
 *     ```
       <?php
       /*
       Plugin Name: Mallona Memberlist
       Description: ~
       Version: 1.0
       Author: Dominique de Graaff
       Author URI: mailto:d.degraaff@mallona.nl
       */
       if (!class_exists('Memberlist_Plugin'))
       {
         class Memberlist_Plugin
         {
           public $_name;
           public $page_title;
           public $page_name;
           public $page_id;
   
           public function __construct()
           {
             $this->_name      = 'memberlist';
             $this->page_title = 'Memberlist';
             $this->page_name  = $this->_name;
             $this->page_id    = '0';
   
             register_activation_hook(__FILE__, array($this, 'activate'));
             register_deactivation_hook(__FILE__, array($this, 'deactivate'));
             register_uninstall_hook(__FILE__, array($this, 'uninstall'));
   
             add_filter('parse_query', array($this, 'query_parser'));
             add_filter('the_posts', array($this, 'page_filter'));
           }
   
           public function activate()
           {
             global $wpdb;      
   
             delete_option($this->_name.'_page_title');
             add_option($this->_name.'_page_title', $this->page_title, '', 'yes');
   
             delete_option($this->_name.'_page_name');
             add_option($this->_name.'_page_name', $this->page_name, '', 'yes');
   
             delete_option($this->_name.'_page_id');
             add_option($this->_name.'_page_id', $this->page_id, '', 'yes');
   
             $the_page = get_page_by_title($this->page_title);
   
             if (!$the_page)
             {
               // Create post object
               $_p = array();
               $_p['post_title']     = $this->page_title;
               $_p['post_content']   = "This text may be overridden by the plugin. You shouldn't edit it.";
               $_p['post_status']    = 'publish';
               $_p['post_type']      = 'page';
               $_p['comment_status'] = 'closed';
               $_p['ping_status']    = 'closed';
               $_p['post_category'] = array(1); // the default 'Uncatrgorised'
   
               // Insert the post into the database
               $this->page_id = wp_insert_post($_p);
             }
             else
             {
               // the plugin may have been previously active and the page may just be trashed...
               $this->page_id = $the_page->ID;
   
               //make sure the page is not trashed...
               $the_page->post_status = 'publish';
               $this->page_id = wp_update_post($the_page);
             }
   
             delete_option($this->_name.'_page_id');
             add_option($this->_name.'_page_id', $this->page_id);
           }
   
           public function deactivate()
           {
             $this->deletePage();
             $this->deleteOptions();
           }
   
           public function uninstall()
           {
             $this->deletePage(true);
             $this->deleteOptions();
           }
   
           public function query_parser($q)
           {
             if(isset($q->query_vars['page_id']) AND (intval($q->query_vars['page_id']) == $this->page_id ))
             {
               $q->set($this->_name.'_page_is_called', true);
             }
             elseif(isset($q->query_vars['pagename']) AND (($q->query_vars['pagename'] == $this->page_name) OR ($_pos_found = strpos($q->query_vars['pagename'],$this->page_name.'/') === 0)))
             {
               $q->set($this->_name.'_page_is_called', true);
             }
             else
             {
               $q->set($this->_name.'_page_is_called', false);
             }
           }
   
           function page_filter($posts)
           {
             global $wp_query;
   
             if($wp_query->get($this->_name.'_page_is_called'))
             {
               $posts[0]->post_title = __('Memberlist');
               $posts[0]->post_content = 'The contents';
             }
             return $posts;
           }
   
           private function deletePage($hard = false)
           {
             global $wpdb;
   
             $id = get_option($this->_name.'_page_id');
             if($id && $hard == true)
               wp_delete_post($id, true);
             elseif($id && $hard == false)
               wp_delete_post($id);
           }
   
           private function deleteOptions()
           {
             delete_option($this->_name.'_page_title');
             delete_option($this->_name.'_page_name');
             delete_option($this->_name.'_page_id');
           }
         }
       }
       $memberlist = new Memberlist_Plugin();
       ?>
       ```
   
 * And what do you guys mean by ‘not’ using a page, but just a blank post. Do you
   have a little example for me that explains this?
 * _By the way, i’m on 3.0 now (if that does matter)_
 * Thanks!
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [custom post type with post_id in permalink structure](https://wordpress.org/support/topic/custom-post-type-permalink-structure/)
 *  Thread Starter [ne0que](https://wordpress.org/support/users/ne0que/)
 * (@ne0que)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/custom-post-type-permalink-structure/#post-1526457)
 * I do not understand why that link counts for us.
 * I’m not dealing with taxomonies. Just a a custom post type ;).
 * **When i go to **
    [http://www.example.com/webspots/18/](http://www.example.com/webspots/18/)
   _or_ [http://www.example.com/webspots/18/kijkers-roepen-wilders-uit-tot-winnaar-debat/](http://www.example.com/webspots/18/kijkers-roepen-wilders-uit-tot-winnaar-debat/)
 * **it should do this:**
    [http://www.example.com/index.php?p=18](http://www.example.com/index.php?p=18)
 * Nothing more, nothing less. Thats all.
 * then based on the content type it will be loaded in it’s own template.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [custom post type with post_id in permalink structure](https://wordpress.org/support/topic/custom-post-type-with-post_id-in-permalink-structure/)
 *  Thread Starter [ne0que](https://wordpress.org/support/users/ne0que/)
 * (@ne0que)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/custom-post-type-with-post_id-in-permalink-structure/#post-1526915)
 * Eating my hat here
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [custom post type with post_id in permalink structure](https://wordpress.org/support/topic/custom-post-type-permalink-structure/)
 *  Thread Starter [ne0que](https://wordpress.org/support/users/ne0que/)
 * (@ne0que)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/custom-post-type-permalink-structure/#post-1526350)
 *     ```
       add_filter('post_type_link', 'webspot_type_link', 1, 3);
       function webspot_type_link($post_link, $id = 0, $leavename = false)
           {
             if (strpos('%webspot_id%', $post_link) < 0)
             {
               return $post_link;
             }
             $post = get_post($id);
   
             if (!is_object($post) || $post->post_type != 'webspot')
             {
               return $post_link;
             }
             return str_replace('%webspot_id%', $post->ID, $post_link);
           }
       ```
   
 * Makes the link correctly. But when i press on ‘view’ i get redirected to a 404
   page. The URL is good:
 * `http://www.domain.com/webspots/47/vliegtuig-met-brandende-motor-maakt-noodlanding-
   schiphol/`
 * It gives me a 404 error.
 * What must i do more to let this work ?
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [custom post type with post_id in permalink structure](https://wordpress.org/support/topic/custom-post-type-permalink-structure/)
 *  Thread Starter [ne0que](https://wordpress.org/support/users/ne0que/)
 * (@ne0que)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/custom-post-type-permalink-structure/#post-1526274)
 * Nobody has a clue?

Viewing 5 replies - 1 through 5 (of 5 total)