Support » Plugins » Hacks » Custom post type and permalinks

  • Hi all!
    I have an issue with my plugin:
    I want to declare a custom post-type “flip_pong”, in a class “flippong”.
    Untill here, everything is ok. The issue happens when I want to see a post of this CTP with pretty permalinks: 404 error !

    I know I have to call flush_rewrite_rules() to rewrite the permalinks structure. So I call it at the plugin activation. Everything seems to work, except that I still have a 404 when I want to see a post.

    If anyone have an idea about what I’m doing wrong..
    Here’s my code:

    class flippong{
    function create_flippong_post_types() {
    	register_post_type( 'flip_pong',
    			'labels' => array(
    				'name' => __( 'Flipbooks' ),
    				'singular_name' => __( 'Flipbook' ),
    					'add_new' => __( 'add new' ),
    					'add_new_item' => __( 'add a FlipBook' ),
    					'edit' => __( 'edit' ),
    					'edit_item' => __( 'edit FlipBook' ),
    					'new_item' => __( 'new FlipBook;' ),
    					'view' => __( 'see' ),
    					'view_item' => __( 'see FlipBook' ),
    					'search_items' => __( 'search FlipBook' ),
    					'not_found' => __( 'no FlipBook found' ),
    			'public' => true,
    			'taxonomies' => array('category'),
    			'show_ui' => true,
    			'publicly_queryable' => true,
    			'rewrite' => array( 'slug' => 'flip_pong' ),
    			'menu_icon' => plugins_url().'/flip-pong-v/images/book.png',
    			'supports' => array('title','editor','thumbnail')
    }//end class
    add_action('init', array('flippong','create_flippong_post_types' ));
    register_activation_hook( __FILE__, array('flippong','create_flippong_post_types' ) );
    register_activation_hook( __FILE__, 'flush_rewrite_rules' );
    register_deactivation_hook( __FILE__, 'flush_rewrite_rules' );

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz


    You need to use the array('flippong','create_flippong_post_types' ) form of referencing your class method for add_action() and anywhere you pass a function name to be used as a callback.

    You should call the flush_rewrite_rule() function from your own activation and deactivation callbacks instead of hooking it separately. As it is now, you cannot be sure it will be called in the right sequence.

    Thanks for your help.
    About the array(‘flippong’,’create_flippong_post_types’ ), that’s exactly what I did, no ?

    Anyway, listening to your advices, I now have this:

    class flippong{
    function create_flippong_post_types() {
    public static function flippong_activate() {
    public static function flippong_deactivate() {
    }//end class
    add_action('init', array('flippong','create_flippong_post_types' ));
    register_activation_hook( __FILE__, array('flippong','flippong_activate' ));
    register_deactivation_hook( __FILE__, array('flippong','flippong_deactivate' ));

    but it doesn’t change anything. The flush_rewrite_rules() function doesn’t seem to include my new post type: I still have 404 error.

    Any idea ?

    Moderator bcworkz


    Er, yeah, that’s what you did. I must be blind! How embarrassing, sorry about that. I’ve looked over your code again, carefully this time, and see nothing wrong. Not reassuring since I’ve been proven blind :/

    You could try toggling the permalink settings off and on in your admin panel to see if the issue is the activation hook or something else, maybe something in .htaccess taking action before the WP section? Sorry, I’m not coming up with any useful ideas.

    Toggling the permalink settings off and on is solving the problem.
    But that’s the point: I want users have to do that…

    I don’t get why the flush_rewrite_rules() isn’t working.

    Anyone have an idea ?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom post type and permalinks’ is closed to new replies.