WordPress.org

Ready to get started?Download WordPress

Forums

Custom Taxonomy Archive Template Doesn't Think I Have Posts (6 posts)

  1. GusRuss89
    Member
    Posted 1 year ago #

    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.

  2. YouON
    Member
    Posted 1 year ago #

    Are you sure 'taxonomy-grower_posts' is it correct? Why have you used the underscore "_" instead the "-"? Normally the slug needs the minus sign...

  3. GusRuss89
    Member
    Posted 1 year ago #

    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.

  4. YouON
    Member
    Posted 1 year ago #

    Can you post the complete code?

  5. GusRuss89
    Member
    Posted 1 year ago #

    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 );
    }
  6. YouON
    Member
    Posted 1 year ago #

    Ok can you post also the loop?

Topic Closed

This topic has been closed to new replies.

About this Topic