I'm using a Custom Post Type (CPT) my-project stored in a custom table MY_PROJECT.

Here is the CPT registering code:

    $labels = array(
        'name' => __( 'Projects ' ),
        'singular_name' => __( 'Project' ),
                    // other labels

    $args = array(
        'labels' => $labels,
        'description' => __( 'Projects Management' ),
        'public' => true,
        'show_ui' => true,
        'show_in_nav_menus' => true,
        'show_in_admin_bar' => true,
        'menu_position' => 100,
        'capability_type' => 'post',
        'hierarchical' => false,
        'has_archive' => true,
        'supports' => false,
        'publicly_queryable' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'project', 'with_front' => false ),

    register_post_type( 'my-project', $args );

As you can see I don't use any fields from Wordpress ('supports' => false,) as I'm using my own fields and insert them in my custom table; but I set post-name and post-title in wp_posts table when creating a new CPT my-project.

I want to display all my fields using basic template twentyeleven, I found that I have to add this code in themes/twentyeleven/functions.php:

add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
    if ( is_home() )
    $query->set( 'post_type', array( 'my-project' ) );
return $query;

=> First question: is there another way to register my CPT to display it/ is that the best place to write this?

Then I created 2 files in themes/twentyeleven/:

1 archive-my-project.php (should display list of my-project)

2 single-my-project.php (should display one my-project)

=> Second question, using "Preview before modification" button in admin will display a list of all my CPT my-project (only the title). It should be only one project, and wordpress should use single-my-project.php file right? The URL is ok: http://localhost/wordpress/project/project1/. And clicking on one of the title will display "Nothing found" page... I tried to editsingle-my-project.php content to display "TEST" string but nothing changed...

=> Third question: slug (which I set to project) is used only in the URL and nowhere else, is that right? Nothing to do with file names single-my-project.php (ok) / single-project.php (not ok)?

Please note I've read about Template_Hierarchy

Thanks for your help,



1 Answer 1


Question #1: I don't really understand this question, but what you have done looks alright. I might add the pre_get_posts filter in the same place as register the post type-- presumably a plugin file-- but registering in the theme should work. It won't transfer to another theme if you do that though.

Question #2: You have to flush the permalinks when you register a new CPT. There are a number of questions and answers here concerning that. Recently, I answered this one: https://wordpress.stackexchange.com/a/99014/21376 The short version of the story is "Go to wp-admin->Settings->Permalinks and click the save button".

Qustions #3: The file names come from the name (slug) you use to register to post type-- the first parameter here: register_post_type( 'my-project', $args );. The other arguments do not effect that, as far as I know.

  • Thanks for your reply. I didn't know about the flush process, it doesnt work for me but it's ok when doing "Go to wp-admin->Settings->Permalinks and click the save button". I'll try to sort this out. It still using the templates/twentyeleven/index.php file instead of single-my-project.php or archive-my-project.php files, don't know why. I'll come back later if I can find any solution in the process. Thank you.
    – Xavier
    Commented May 12, 2013 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.