Support » Fixing WordPress » Custom Taxonomy Archive Template Doesn't Think I Have Posts

  • I have a custom taxonomy assigned to a custom post type.

    I’ve created a template called 'taxonomy-grower_posts', which gets called when I visit a custom taxonomy, however when I call the loop in this template, it doesn’t think I have any posts (it skips the if(have_posts()) and executes the else {}).

    My custom post type has 'has_archive' => true, and when I go to the archive page for the post type I see the archive.

    Am I overlooking something else?

    Thanks in advance for your help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Are you sure ‘taxonomy-grower_posts’ is it correct? Why have you used the underscore “_” instead the “-“? Normally the slug needs the minus sign…

    Thanks for the reply.

    It’s definitely correct. The template actually works, it’s just that the loop doesn’t work inside it – or it doesn’t think it has any actual posts.

    Can you post the complete code?

    This is the code that creates the custom taxonomy. My guess is that it must be a problem somewhere in here.

    /* Add a new "categories" taxonomy to growers posts */
    add_action( 'init', 'create_grower_taxonomy', 0 );
    function create_grower_taxonomy() {
      // Add new taxonomy, make it hierarchical (like categories)
      $labels = array(
        'name'                => _x( 'Categories', 'taxonomy general name' ),
        'singular_name'       => _x( 'Category', 'taxonomy singular name' ),
        'search_items'        => __( 'Search Categories' ),
        'all_items'           => __( 'All Categories' ),
        'parent_item'         => __( 'Parent Category' ),
        'parent_item_colon'   => __( 'Parent Category:' ),
        'edit_item'           => __( 'Edit Category' ),
        'update_item'         => __( 'Update Category' ),
        'add_new_item'        => __( 'Add New Category' ),
        'new_item_name'       => __( 'New Category Name' ),
        'menu_name'           => __( 'Categories' )
      $args = array(
        'hierarchical'        => true,
        'labels'              => $labels,
        'show_ui'             => true,
        'show_admin_column'   => true
        //'query_var'           => true
        //'rewrite'             => array( 'slug' => 'gp_categories' )
      register_taxonomy( 'gp_categories', array( 'grower_posts' ), $args );

    Ok can you post also the loop?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Taxonomy Archive Template Doesn't Think I Have Posts’ is closed to new replies.